Why don't I get a method error?
I'm a rails programmer. And rails always 开发者_开发技巧tells me that I've got "NoMethodError". Why don't I get a MethodError? I want a MethodError.
Please help me.
Edit:
Here's my code:
42.this_is_a_method
Ruby doesn't have a MethodError. But you can make one!
class MethodError < NoMethodError; end
Now, catch all the NoMethodErrors in this way:
class Object
def method_missing(m)
raise MethodError, "undefined method `#{m}' for #{self.inspect}:#{self.class}"
end
end
You would be getting a NoMethodError
because the Fixnum
class doesn't have a this_is_a_method
defined for instances of that class.
精彩评论