summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-12-22 21:30:32 -0800
committerJeremy Evans <code@jeremyevans.net>2020-12-23 19:29:19 -0800
commit1e215a66d26d56befab4fbb72e1d953879411955 (patch)
tree1633af4390f554711ca04b50566f544d84ee9f9e /spec/ruby
parent9aca51e8a597fb4689c058b4e6b215ae87434e1b (diff)
Fix class of method in Method#inspect for singleton classes of classes
Previously, due to a change to fix bug 15608, Method#inspect output changed for class methods: Ruby 2.7 "#<Method: String.prepend(*)>" Before change: "#<Method: #<Class:Object>(Module)#prepend(*)>" This is wrong because the Method object was created from String and not Object. This is because the fix for bug 15608 assumed it was being called on the singleton class of a instance, and would skip the first singleton class until it got to the class itself. For class methods, this results in always using the superclass. Fix behavior to not skip until the superclass if the singleton class is the singleton class of a module or class. After change: "#<Method: #<Class:Object>(Module)#prepend(*)>" Fixes [Bug #17428]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3984
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/core/method/shared/to_s.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb
index 1fbee870d6..8f7dd8c161 100644
--- a/spec/ruby/core/method/shared/to_s.rb
+++ b/spec/ruby/core/method/shared/to_s.rb
@@ -62,6 +62,12 @@ describe :method_to_s, shared: true do
@m = obj.method(:bar)
@string = @m.send(@method)
@string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
+
+ c = MethodSpecs::MySub.dup
+ m = Module.new{def bar; end}
+ c.extend(m)
+ @string = c.method(:bar).send(@method)
+ @string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar"
end
end