* lib/ostruct.rb (OpenStruct#inspect): fixed the recursion check.
Patch by Kornelius Kalnbach. [ruby-core:20992]. * test/ostruct/test_ostruct.rb: test for inspect. Patch by Kornelius Kalnbach. [ruby-core:20992]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
be551172ed
commit
ed15422759
10
ChangeLog
10
ChangeLog
@ -1,3 +1,11 @@
|
|||||||
|
Tue Jan 13 21:45:53 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
|
* lib/ostruct.rb (OpenStruct#inspect): fixed the recursion check.
|
||||||
|
Patch by Kornelius Kalnbach. [ruby-core:20992].
|
||||||
|
|
||||||
|
* test/ostruct/test_ostruct.rb: test for inspect.
|
||||||
|
Patch by Kornelius Kalnbach. [ruby-core:20992].
|
||||||
|
|
||||||
Tue Jan 13 21:44:30 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Jan 13 21:44:30 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (io_reopen, rb_io_init_copy): should register fptr to pipe_list
|
* io.c (io_reopen, rb_io_init_copy): should register fptr to pipe_list
|
||||||
@ -16,7 +24,7 @@ Tue Jan 13 21:38:07 2009 Tanaka Akira <akr@fsij.org>
|
|||||||
Tue Jan 13 21:28:14 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
Tue Jan 13 21:28:14 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
* object.c (rb_obj_not_match): rdoc.
|
* object.c (rb_obj_not_match): rdoc.
|
||||||
Patch by Kornelius Kalnbach.
|
Patch by Kornelius Kalnbach. [ruby-core:20991]
|
||||||
|
|
||||||
Tue Jan 13 18:21:44 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Jan 13 18:21:44 2009 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
@ -112,25 +112,23 @@ class OpenStruct
|
|||||||
def inspect
|
def inspect
|
||||||
str = "#<#{self.class}"
|
str = "#<#{self.class}"
|
||||||
|
|
||||||
Thread.current[InspectKey] ||= []
|
ids = (Thread.current[InspectKey] ||= [])
|
||||||
if Thread.current[InspectKey].include?(self) then
|
if ids.include?(object_id)
|
||||||
str << " ..."
|
return str << ' ...>'
|
||||||
else
|
end
|
||||||
|
|
||||||
|
ids << object_id
|
||||||
|
begin
|
||||||
first = true
|
first = true
|
||||||
for k,v in @table
|
for k,v in @table
|
||||||
str << "," unless first
|
str << "," unless first
|
||||||
first = false
|
first = false
|
||||||
|
str << " #{k}=#{v.inspect}"
|
||||||
Thread.current[InspectKey] << v
|
|
||||||
begin
|
|
||||||
str << " #{k}=#{v.inspect}"
|
|
||||||
ensure
|
|
||||||
Thread.current[InspectKey].pop
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
return str << '>'
|
||||||
|
ensure
|
||||||
|
ids.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
str << ">"
|
|
||||||
end
|
end
|
||||||
alias :to_s :inspect
|
alias :to_s :inspect
|
||||||
|
|
||||||
|
@ -20,4 +20,18 @@ class TC_OpenStruct < Test::Unit::TestCase
|
|||||||
o2.instance_eval{@table = {:a => 'b'}}
|
o2.instance_eval{@table = {:a => 'b'}}
|
||||||
assert_not_equal(o1, o2)
|
assert_not_equal(o1, o2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_inspect
|
||||||
|
foo = OpenStruct.new
|
||||||
|
assert_equal("#<OpenStruct>", foo.inspect)
|
||||||
|
foo.bar = 1
|
||||||
|
foo.baz = 2
|
||||||
|
assert_equal("#<OpenStruct bar=1, baz=2>", foo.inspect)
|
||||||
|
|
||||||
|
foo = OpenStruct.new
|
||||||
|
foo.bar = OpenStruct.new
|
||||||
|
assert_equal('#<OpenStruct bar=#<OpenStruct>>', foo.inspect)
|
||||||
|
foo.bar.foo = foo
|
||||||
|
assert_equal('#<OpenStruct bar=#<OpenStruct foo=#<OpenStruct ...>>>', foo.inspect)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user