module Util
def hello
puts "hello"
end
end
class Company
include Util
end
class Company2
extend Util
end
c = Company.new
c.hello
Company2.hello
オブジェクトにmoduleをインクルードする場合
module Util2
def hello2
puts "hello2"
end
end
com = Company.new
com.extend(Util2)
com.hello2
#これはエラーが発生します。
com2 = Company.new
com2.hello2
0 件のコメント:
コメントを投稿