method_missing
出现在 中Object.private_methods
,而不出现在 中Object.public_methods
。
但是,当我打电话时Object.method_missing :stupidmethod
,我得到
NoMethodError: undefined method `stupidmethod' for Object:Class
我希望得到
NoMethodError: private method `method_missing' called for Object:Class
因为这就是我尝试调用其他私有方法时得到Object
的,例如.Object.chop
作为更多证据,如果我Object.method_missing
在没有争论的情况下打电话,我会得到
ArgumentError: no id given
所以看起来我真的是method_missing
从它的对象之外调用那个“私有”函数。你能解释一下吗?
编辑:感谢评论中的尤金。 ruby --version
告诉我 1.8.7。此外,irb --version
是 0.9.5(05/04/13)。很高兴知道这在以后的版本中表现得如我所料。