在下面的代码,“self.included?”在Ruby中
module Test
@connection = nil
def self.included?(base)
@connection = base
end
def print
puts @connection
end
end
class ModuleTest
include Test
end
m = ModuleTest.new
m.print
为什么@connection
零打印时?
你真的想'@connection = base'更有意义,还是你的意思是'@connection == base'?有一个方法以一个问号结束并且总是返回值,这似乎很奇怪。 – Phrogz 2011-04-29 16:02:10