summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-13 12:52:23 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-13 12:52:23 +0000
commit50df2c8ea0c9ace45a6e879f0c0b6493ac83a5ac (patch)
tree5cb8ebecd95d17f5f861547693a0433b37274dca /lib
parent0c77840313e4f86c645b9cac362f83b3c1028105 (diff)
downloadruby-50df2c8ea0c9ace45a6e879f0c0b6493ac83a5ac.tar.gz
ruby-50df2c8ea0c9ace45a6e879f0c0b6493ac83a5ac.tar.xz
ruby-50df2c8ea0c9ace45a6e879f0c0b6493ac83a5ac.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@21496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/ostruct.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index f3ed01524..35a14b492 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -112,25 +112,23 @@ class OpenStruct
def inspect
str = "#<#{self.class}"
- Thread.current[InspectKey] ||= []
- if Thread.current[InspectKey].include?(self) then
- str << " ..."
- else
+ ids = (Thread.current[InspectKey] ||= [])
+ if ids.include?(object_id)
+ return str << ' ...>'
+ end
+
+ ids << object_id
+ begin
first = true
for k,v in @table
str << "," unless first
first = false
-
- Thread.current[InspectKey] << v
- begin
- str << " #{k}=#{v.inspect}"
- ensure
- Thread.current[InspectKey].pop
- end
+ str << " #{k}=#{v.inspect}"
end
+ return str << '>'
+ ensure
+ ids.pop
end
-
- str << ">"
end
alias :to_s :inspect