1.9.3p327:006>X.helloNoMethodError:undefinedmethod`hello' for X:Module from (irb):6 from /home/john/.rvm/rubies/ruby-1.9.3-p327-falcon/bin/irb:16:in `<main>'
moduleXdefself.hello;'hello';enddefself.world;'world';endend# in irb1.9.3p327:007>X.hello=>"hello"
对于方法很多的 module ,我们可以少写几个self.,只要借助 extend 机制
12345678910111213
moduleXextendselfdefhello;'hello';enddefworld;'world';endend# in irb1.9.3p327:007>X.hello=>"hello"1.9.3p327:008>includeX=>Object1.9.3p327:009>hello=>"hello"
1.9.3p327:008>X.hello=>"hello"1.9.3p327:009>includeX=>Object1.9.3p327:010>helloNameError:undefinedlocalvariableormethod`hello' for main:Object from (irb):10 from /home/john/.rvm/rubies/ruby-1.9.3-p327-falcon/bin/irb:16:in `<main>'