зеркало из https://github.com/github/ruby.git
Method#inspect with source location.
Method#inspect shows with source location. [Feature #14145]
This commit is contained in:
Родитель
4ce935cd5d
Коммит
47b04557b0
12
proc.c
12
proc.c
|
@ -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;
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче