开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜