Skip to content

Commit

Permalink
Don't use Object#inspect in Kernel#method
Browse files Browse the repository at this point in the history
As discussed already in #3373 some people might overwrite this in a way
that's not compatible with the default behaviour.

While we can't (and are not going to) guard ourselves against every
possible case where somebody might've overwritten a core Ruby method, we
_can_ at least in this particular case remove the dependency on
Object#inspect. As an aside this now ensures that our error messages are
the same as MRI's, although one could argue that this is a bit odd:

    class Foo
    end

    Foo.method(:bar) # => NameError: undefined method `barr' for class `Class'

Instead of:

    Foo.method(:bar) # => NameError: undefined method `barr' for class `Foo'
  • Loading branch information
Yorick Peterse committed Apr 21, 2015
1 parent 0ec0c5c commit 76701eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/common/kernel.rb
Expand Up @@ -524,7 +524,7 @@ def method(name)
elsif respond_to_missing?(name, true)
Method.new(self, self.class, Rubinius::MissingMethod.new(self, name), name)
else
raise NameError, "undefined method `#{name}' for #{self.inspect}"
raise NameError, "undefined method `#{name}' for class #{self.class}"
end
end

Expand Down

0 comments on commit 76701eb

Please sign in to comment.