我試圖定義和調用函數new
:命令的方法`內忽略new`
module Me
class Bobkat
def new()
puts "Kernel.caller()[0].to_s() is " << Kernel.caller()[0].to_s()
initialize()
end
def initialize
return self
end
end
end
Me::Bobkat.new()
它忽略了puts
命令。我想知道爲什麼它這樣做。有任何想法嗎?
順便說一句,在[默認實現(http://ruby-doc.org/core-2.2.3/Class.html #method-i-new)調用'allocate'創建一個新對象,調用對象的'initialize'方法(傳遞任何參數)並返回該對象。 – Stefan