diff options
author | wyhaines <wyhaines@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-10 14:50:32 +0000 |
---|---|---|
committer | wyhaines <wyhaines@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-10 14:50:32 +0000 |
commit | c5b3b3c3f8be69f46c2c2d85c4c09d83132c659c (patch) | |
tree | 553ab1b27bbe1be02df9239ea5c56bedc7af9cf0 | |
parent | c8e0720b4f930028a089f9f5d6d9f04ba2ccbbc3 (diff) | |
download | ruby-c5b3b3c3f8be69f46c2c2d85c4c09d83132c659c.tar.gz ruby-c5b3b3c3f8be69f46c2c2d85c4c09d83132c659c.tar.xz ruby-c5b3b3c3f8be69f46c2c2d85c4c09d83132c659c.zip |
Fixed ostruct recursion inspection.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6@24025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/ostruct.rb | 24 | ||||
-rw-r--r-- | test/ostruct/test_ostruct.rb | 8 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 24 insertions, 14 deletions
@@ -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 6af5bbdac..ba7f061a2 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 24ed17f80..ef83db5d1 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 @@ -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 |