What’s the difference between NameError and NoMethodError in Ruby

Great post:

x = Object.new

x.no_method #=> NoMethodError

 

class Testing

  def vcall_no_method

    no_method #=> NameError

  end

 

  def call_no_method

    self.no_method #=> NoMethodError

  end

end

In essence, when Ruby sees a method call with implicit self (which might be a typo’ed local variable), it raises a NameError, rather than a NoMethodError.

http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/

Leave a Reply

Your email address will not be published. Required fields are marked *