mruby-method/method.c (method_to_s): add location information.

Test updated too.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-10-02 17:55:30 +09:00
parent 0c9fd9cffd
commit e7e22ec6a8
2 changed files with 11 additions and 4 deletions
+8 -1
View File
@@ -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;
}
+3 -3
View File
@@ -230,14 +230,14 @@ assert 'to_s' do
o = Object.new
def o.foo; end
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*>", m.unbind.inspect)
c = Class.new
c.class_eval { def foo; end; }
m = c.new.method(:foo)
assert_equal("#<Method: #{ c.inspect }#foo>", m.inspect)
assert_match("#<Method: #{ c.inspect }#foo*>", m.inspect)
m = c.instance_method(:foo)
assert_equal("#<UnboundMethod: #{ c.inspect }#foo>", m.inspect)
assert_match("#<UnboundMethod: #{ c.inspect }#foo*>", m.inspect)
end
assert 'owner' do