在下面的代碼,「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