[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91570] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods?
From:
eregontp@...
Date:
2019-02-15 16:42:35 UTC
List:
ruby-core #91570
Issue #15608 has been reported by Eregon (Benoit Daloze).
----------------------------------------
Bug #15608: What should be the correct output for Method#inspect with singleton methods?
https://bugs.ruby-lang.org/issues/15608
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
bug.rb:
```ruby
class C
def foo
end
end
obj = C.new
class << obj
alias bar foo
end
p obj.method(:foo).owner
p obj.method(:foo)
raise unless obj.method(:foo).owner == C
p obj.method(:bar).owner
p obj.method(:bar)
raise unless obj.method(:bar).owner == obj.singleton_class
```
```
$ chruby 2.0.0
$ ruby -v bug.rb
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x0055b39fcd2c30>>
#<Method: C(C)#foo>
$ chruby 2.3.8
$ ruby -v bug.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
$ chruby 2.4.5
$ ruby -v bug.rb
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
C
#<Method: #<C:0x000055fdc99dc908>.foo>
#<Class:#<C:0x000055fdc99dc908>>
#<Method: #<C:0x000055fdc99dc908>.bar(foo)>
Same for 2.5.3 and 2.6.1
```
I think Method#inspect should show on which Module the method is defined, and only singleton methods should be shown as `receiver.method`, so:
```
C
#<Method: C#foo>
#<Class:#<C:0x000055668ebef268>>
#<Method: #<C:0x000055668ebef268>.bar(foo)>
```
Which only Ruby 2.3 does interestingly.
---
What's the meaning of the `C1(C2)` notation?
It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}(#{owner})` depending on the version:
```ruby
class D < C
end
d = D.new
p d.method(:foo)
d.singleton_class
p d.method(:foo)
```
```
2.0-2.3:
#<Method: D(C)#foo>
#<Method: D(C)#foo>
2.4-2.6:
#<Method: D(C)#foo>
#<Method: #<D:0x000055c12b45e218>.foo>
```
I think the Ruby 2.4+ it's confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method.
Do you agree what I describe should be the correct behavior?
Can we fix it then?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>