mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-method/method.c (method_to_s): add location information.
Test updated too.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user