デザパタ + Python/Ruby/Smalltalk part2at TECH
デザパタ + Python/Ruby/Smalltalk part2 - 暇つぶし2ch25:デフォルトの名無しさん
07/04/10 23:38:09
# abstract.rb

class Module
 def abstract(*names)
  if class_variables.size > 0 then
   class_variable_get(:@@ABSTRACT_METHODS).push *names
  else
   class_variable_set :@@ABSTRACT_METHODS, names
  end
 end
end

module AbstractClass
 def new(*args)
  obj = super(*args)
  class_variable_get(:@@ABSTRACT_METHODS).each do |m|
   unless obj.methods.include?(m.to_s) then
    raise format("Abstract method `%s' not defined", m.to_s)
   end
  end
  return obj
 end
end



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch