Issue #17428 has been updated by Eregon (Benoit Daloze).


With a trivial fix (using the actual class/rb_class_of(), not just `.class`), I get this in TruffleRuby, which I think is the correct output:
```
$ ruby -e 'p String.method(:prepend)'
#<Method: #<Class:String>(Module)#prepend(*modules) <internal:core> core/module.rb:92>

$ ruby -e 'p String.method(:prepend).unbind'
#<UnboundMethod: #<Class:String>(Module)#prepend(*modules) <internal:core> core/module.rb:92>
```

You'll notice it's quite close to MRI's output for an UnboundMethod:
```
# #<Class:Object> instead of #<Class:String> is the bug, the rest is fine
$ ruby-master -e 'p String.method(:prepend).unbind'
#<UnboundMethod: #<Class:Object>(Module)#prepend(*)>

$ ruby-2.7.2 -e 'p String.method(:prepend).unbind'
#<UnboundMethod: #<Class:String>#prepend(*)>
```

The actual logic for Method#inspect and and UnboundMethod#inspect should be similar, and I think the logic in TruffleRuby is correct and makes the most sense:
https://github.com/oracle/truffleruby/blob/0aeb60024d025e3d3d836bd08ff89479d4292bb7/src/main/ruby/truffleruby/core/truffle/method_operations.rb#L37-L42

The crucial part for this case: only use the `.` notation if the owner of the method (Method#owner) is a singleton class, *not* if the receiver has a singleton class.
```
# All Rubies agree on:
$ ruby -e 'p String.method(:prepend).owner.singleton_class?'
false
```


----------------------------------------
Bug #17428: Method#inspect bad output for class methods
https://bugs.ruby-lang.org/issues/17428#change-89438

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: jeremyevans0 (Jeremy Evans)
* ruby -v: ruby 3.0.0dev (2020-12-22T17:37:59Z master 487355873a) [x86_64-darwin18]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
```
$ $ ruby -e 'p String.method(:prepend)'
# 2.7.0:
#<Method: String.prepend(*)>
# 3.0.0:
#<Method: #<Class:Object>(Module)#prepend(*)>
```

@jeremyevans found it shows the method as pertaining to one level too high (which is good for objects as we don't want to show the singleton class there, but not for classes).

Probably due to #15608



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>