diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-03-09 07:57:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 07:57:16 -0700 |
commit | e02bd0e713ef920e6d12c27f16548f48ec5c2cf0 (patch) | |
tree | a04c6ec68aa6c9d177d09ebb5fc79bb0ece3af7e /spec | |
parent | ecef163cf9bbdffcf1466addc39daa92084d6b53 (diff) | |
download | ruby-e02bd0e713ef920e6d12c27f16548f48ec5c2cf0.tar.gz |
Don't display singleton class in Method#inspect unless method defined there
Previously, if an object has a singleton class, and you call
Object#method on the object, the resulting string would include
the object's singleton class, even though the method was not
defined in the singleton class.
Change this so the we only show the singleton class if the method
is defined in the singleton class.
Fixes [Bug #15608]
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/method/shared/to_s.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb index 373398a785..7666322936 100644 --- a/spec/ruby/core/method/shared/to_s.rb +++ b/spec/ruby/core/method/shared/to_s.rb @@ -31,4 +31,22 @@ describe :method_to_s, shared: true do it "returns a String containing the Module the method is referenced from" do @string.should =~ /MethodSpecs::MySub/ end + + ruby_version_is '2.8' do + it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do + obj = MethodSpecs::MySub.new + obj.singleton_class + @m = obj.method(:bar) + @string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX') + @string.should =~ /\A#<Method: MethodSpecs::MySub\(MethodSpecs::MyMod\)#bar\(\) / + end + end + + it "returns a String containing the singleton class if method is defined in the singleton class" do + obj = MethodSpecs::MySub.new + def obj.bar; end + @m = obj.method(:bar) + @string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX') + @string.should =~ /\A#<Method: #<MethodSpecs::MySub:0xXXXXXX>\.bar/ + end end |