明白为什么这么写了,自问自答一下:前一种支持直接 include X,然后调用内部方法,后一种避免了 include 以后污染当前变量空间
1.9.3p327:001>moduleX1.9.3p327:002?>extendModule.new{1.9.3p327:003>defhello;'hello';end1.9.3p327:004?>defworld;'world';end1.9.3p327:005?>}1.9.3p327:006?>end=>X1.9.3p327:007>X.hello=>"hello"1.9.3p327:008>includeX=>Object1.9.3p327:009>helloNameError:undefinedlocalvariableormethod`hello' for main:Object
from (irb):9
from /home/john/.rvm/rubies/ruby-1.9.3-p327-falcon/bin/irb:16:in `<main>'