summaryrefslogtreecommitdiff
path: root/lib/ostruct.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r--lib/ostruct.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index f3ed01524b..35a14b4920 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