Thursday, 19 September 2013

method_missing visibility in Ruby

method_missing visibility in Ruby

method_missing shows up in Object.private_methods, not in
Object.public_methods.
However, when I call Object.method_missing :stupidmethod, I get
NoMethodError: undefined method `stupidmethod' for Object:Class
I would expect to get
NoMethodError: private method `method_missing' called for Object:Class
because that's what I get when I try to invoke Object's other private
methods, e.g. Object.chop.
As more evidence, if I call Object.method_missing without an argument, I get
ArgumentError: no id given
So it seems like I really am invoking that "private" method_missing
function from outside of its object. Can you explain this?

No comments:

Post a Comment