aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2020-09-05 19:18:07 +0900
committernagachika <nagachika@ruby-lang.org>2020-09-05 19:18:07 +0900
commit2c9dd060ab487a96e391793bd782cef6fd471b83 (patch)
tree478740c545cc1a1bc6ff02600e1b18d79016993f
parente9e4f8430a62f56a4e62dd728f4498ee4c300c12 (diff)
downloadruby-2c9dd060ab487a96e391793bd782cef6fd471b83.tar.gz
Revert "Don't display singleton class in Method#inspect unless method defined there"
[Backport #16771] This reverts commit 0d24fb774d84d4a99454ce10fd343da00049a588.
-rw-r--r--proc.c9
-rw-r--r--spec/ruby/core/method/shared/to_s.rb18
-rw-r--r--test/ruby/test_method.rb8
3 files changed, 1 insertions, 34 deletions
diff --git a/proc.c b/proc.c
index 020505ae72..e189c20886 100644
--- a/proc.c
+++ b/proc.c
@@ -2816,8 +2816,7 @@ method_inspect(VALUE method)
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
str = rb_sprintf("#<% "PRIsVALUE": ", rb_obj_class(method));
- mklass = data->iclass;
- if (!mklass) mklass = data->klass;
+ mklass = data->klass;
if (RB_TYPE_P(mklass, T_ICLASS)) {
/* TODO: I'm not sure why mklass is T_ICLASS.
@@ -2857,12 +2856,6 @@ method_inspect(VALUE method)
}
}
else {
- mklass = data->klass;
- if (FL_TEST(mklass, FL_SINGLETON)) {
- do {
- mklass = RCLASS_SUPER(mklass);
- } while (RB_TYPE_P(mklass, T_ICLASS));
- }
rb_str_buf_append(str, rb_inspect(mklass));
if (defined_class != mklass) {
rb_str_catf(str, "(% "PRIsVALUE")", defined_class);
diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb
index 7666322936..373398a785 100644
--- a/spec/ruby/core/method/shared/to_s.rb
+++ b/spec/ruby/core/method/shared/to_s.rb
@@ -31,22 +31,4 @@ 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
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 6ad9620a00..bb506f1258 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -459,14 +459,6 @@ class TestMethod < Test::Unit::TestCase
c3.class_eval { alias bar foo }
m3 = c3.new.method(:bar)
assert_equal("#<Method: #{c3.inspect}(#{c.inspect})#bar(foo)() #{__FILE__}:#{line_no}>", m3.inspect, bug7806)
-
- bug15608 = '[ruby-core:91570] [Bug #15608]'
- c4 = Class.new(c)
- c4.class_eval { alias bar foo }
- o = c4.new
- o.singleton_class
- m4 = o.method(:bar)
- assert_equal("#<Method: #{c4.inspect}(#{c.inspect})#bar(foo)() #{__FILE__}:#{line_no}>", m4.inspect, bug15608)
end
def test_callee_top_level