include 和 extend的使用
使用inluce 将一个模块包含到一个类中 ,并以此方式来访问模块中的实例成员。
extend 方法主要用来在一个对象中引入一个模块,这个类就具备了这个模块的方法,类似于继承。如果想要使模块中的方法成为类方法时,就需要使用extend方法。
[ruby]
#encoding:gbk
puts "#{File.dirname(__FILE__)}";
module Mood
def say
puts "hello";
end
end
class Person
end
person = Person.new
person.extend(Mood);
person.say;