我试图定义和调用函数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