summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/ostruct.rb24
-rw-r--r--test/ostruct/test_ostruct.rb8
-rw-r--r--version.h2
4 files changed, 24 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f7d213651..eea1344842 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,10 @@ Thu Jul 9 11:22:00 2009 Kirk Haines <khaines@ruby-lang.org>
* configure.in: Little fixes for x64 libdir/sitedir.
+ * lib/ostruct.rb: Fixed buggy openstruct#inspect recursion.
+
+ * test/ostruct/test_ostruct.rb: Modified tests to fit the #inspect fix.
+
Mon Jun 8 12:46:00 2009 Kirk Haines <khaines@ruby-lang.org>
* lib/soap/mimemessage.rb: Fixed a typo -- conent -> content
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 6af5bbdac0..ba7f061a22 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -111,25 +111,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
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 24ed17f800..ef83db5d15 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -20,4 +20,12 @@ class TC_OpenStruct < Test::Unit::TestCase
o2.instance_eval{@table = {:a => 'b'}}
assert_not_equal(o1, o2)
end
+
+ def test_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
diff --git a/version.h b/version.h
index d2d83e7c30..c8c09c246c 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2009-06-08"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20090608
-#define RUBY_PATCHLEVEL 375
+#define RUBY_PATCHLEVEL 376
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8