diff options
author | Koichi Sasada <ko1@atdot.net> | 2019-07-14 15:42:55 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2019-07-14 15:46:07 +0900 |
commit | 47b04557b01dc109ccafc33db8e80148f07457a9 (patch) | |
tree | 8c11cbfd7f1982ef7284c2a10a3ddf2fbee35c1d | |
parent | 4ce935cd5dde69b39bb98b8948d41e3afba81e33 (diff) |
Method#inspect with source location.
Method#inspect shows with source location.
[Feature #14145]
-rw-r--r-- | proc.c | 12 | ||||
-rw-r--r-- | test/ruby/test_method.rb | 16 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 2 |
3 files changed, 21 insertions, 9 deletions
@@ -2743,6 +2743,18 @@ method_inspect(VALUE method) if (data->me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) { rb_str_buf_cat2(str, " (not-implemented)"); } + + // parameter information + // TODO + + { // source location + VALUE loc = rb_method_location(method); + if (!NIL_P(loc)) { + rb_str_catf(str, " %"PRIsVALUE":%"PRIsVALUE, + RARRAY_AREF(loc, 0), RARRAY_AREF(loc, 1)); + } + } + rb_str_buf_cat2(str, ">"); return str; diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 4e20534dfa..ba425a4517 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -432,29 +432,29 @@ class TestMethod < Test::Unit::TestCase def test_inspect o = Object.new - def o.foo; end + def o.foo; end; line_no = __LINE__ m = o.method(:foo) - assert_equal("#<Method: #{ o.inspect }.foo>", m.inspect) + assert_equal("#<Method: #{ o.inspect }.foo #{__FILE__}:#{line_no}>", m.inspect) m = o.method(:foo) - assert_equal("#<UnboundMethod: #{ class << o; self; end.inspect }#foo>", m.unbind.inspect) + assert_match("#<UnboundMethod: #{ class << o; self; end.inspect }#foo #{__FILE__}:#{line_no}", m.unbind.inspect) c = Class.new - c.class_eval { def foo; end; } + c.class_eval { def foo; end; }; line_no = __LINE__ m = c.new.method(:foo) - assert_equal("#<Method: #{ c.inspect }#foo>", m.inspect) + assert_equal("#<Method: #{ c.inspect }#foo #{__FILE__}:#{line_no}>", m.inspect) m = c.instance_method(:foo) - assert_equal("#<UnboundMethod: #{ c.inspect }#foo>", m.inspect) + assert_equal("#<UnboundMethod: #{ c.inspect }#foo #{__FILE__}:#{line_no}>", m.inspect) c2 = Class.new(c) c2.class_eval { private :foo } m2 = c2.new.method(:foo) - assert_equal("#<Method: #{ c2.inspect }(#{ c.inspect })#foo>", m2.inspect) + assert_equal("#<Method: #{ c2.inspect }(#{ c.inspect })#foo #{__FILE__}:#{line_no}>", m2.inspect) bug7806 = '[ruby-core:52048] [Bug #7806]' c3 = Class.new(c) c3.class_eval { alias bar foo } m3 = c3.new.method(:bar) - assert_equal("#<Method: #{c3.inspect}(#{c.inspect})#bar(foo)>", m3.inspect, bug7806) + assert_equal("#<Method: #{c3.inspect}(#{c.inspect})#bar(foo) #{__FILE__}:#{line_no}>", m3.inspect, bug7806) m.taint assert_predicate(m.inspect, :tainted?, "inspect result should be infected") diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 604edf5f59..37045ad0d9 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -2313,7 +2313,7 @@ class TestModule < Test::Unit::TestCase A.prepend InspectIsShallow - expect = "#<Method: A(ShallowInspect)#inspect(shallow_inspect)>" + expect = "#<Method: A(ShallowInspect)#inspect(shallow_inspect) -:7>" assert_equal expect, A.new.method(:inspect).inspect, "#{bug_10282}" RUBY end |