From e7e22ec6a89728f093393747f6567254c1cd2a65 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 2 Oct 2022 17:55:30 +0900 Subject: [PATCH] mruby-method/method.c (method_to_s): add location information. Test updated too. --- mrbgems/mruby-method/src/method.c | 9 ++++++++- mrbgems/mruby-method/test/method.rb | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mrbgems/mruby-method/src/method.c b/mrbgems/mruby-method/src/method.c index c8f133a30..18560d159 100644 --- a/mrbgems/mruby-method/src/method.c +++ b/mrbgems/mruby-method/src/method.c @@ -423,7 +423,14 @@ method_to_s(mrb_state *mrb, mrb_value self) mrb_str_cat_lit(mrb, str, ")#"); mrb_str_concat(mrb, str, name); } - finish: + finish:; + mrb_value loc = method_source_location(mrb, self); + if (mrb_array_p(loc) && RARRAY_LEN(loc) == 2) { + mrb_str_cat_lit(mrb, str, " "); + mrb_str_concat(mrb, str, RARRAY_PTR(loc)[0]); + mrb_str_cat_lit(mrb, str, ":"); + mrb_str_concat(mrb, str, RARRAY_PTR(loc)[1]); + } mrb_str_cat_lit(mrb, str, ">"); return str; } diff --git a/mrbgems/mruby-method/test/method.rb b/mrbgems/mruby-method/test/method.rb index 9089c96d6..8966ee085 100644 --- a/mrbgems/mruby-method/test/method.rb +++ b/mrbgems/mruby-method/test/method.rb @@ -230,14 +230,14 @@ assert 'to_s' do o = Object.new def o.foo; end m = o.method(:foo) - assert_equal("#", m.unbind.inspect) + assert_match("#", m.unbind.inspect) c = Class.new c.class_eval { def foo; end; } m = c.new.method(:foo) - assert_equal("#", m.inspect) + assert_match("#", m.inspect) m = c.instance_method(:foo) - assert_equal("#", m.inspect) + assert_match("#", m.inspect) end assert 'owner' do