[前][次][番号順一覧][スレッド一覧]

ruby-changes:12330

From: wyhaines <ko1@a...>
Date: Fri, 10 Jul 2009 23:50:45 +0900 (JST)
Subject: [ruby-changes:12330] Ruby:r24025 (ruby_1_8_6): Fixed ostruct recursion inspection.

wyhaines	2009-07-10 23:50:32 +0900 (Fri, 10 Jul 2009)

  New Revision: 24025

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24025

  Log:
    Fixed ostruct recursion inspection.

  Modified files:
    branches/ruby_1_8_6/ChangeLog
    branches/ruby_1_8_6/lib/ostruct.rb
    branches/ruby_1_8_6/test/ostruct/test_ostruct.rb
    branches/ruby_1_8_6/version.h

Index: ruby_1_8_6/ChangeLog
===================================================================
--- ruby_1_8_6/ChangeLog	(revision 24024)
+++ ruby_1_8_6/ChangeLog	(revision 24025)
@@ -12,6 +12,10 @@
 
 	* 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@r...>
 
 	* lib/soap/mimemessage.rb: Fixed a typo -- conent -> content
Index: ruby_1_8_6/version.h
===================================================================
--- ruby_1_8_6/version.h	(revision 24024)
+++ ruby_1_8_6/version.h	(revision 24025)
@@ -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
Index: ruby_1_8_6/lib/ostruct.rb
===================================================================
--- ruby_1_8_6/lib/ostruct.rb	(revision 24024)
+++ ruby_1_8_6/lib/ostruct.rb	(revision 24025)
@@ -111,25 +111,23 @@
   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
 
Index: ruby_1_8_6/test/ostruct/test_ostruct.rb
===================================================================
--- ruby_1_8_6/test/ostruct/test_ostruct.rb	(revision 24024)
+++ ruby_1_8_6/test/ostruct/test_ostruct.rb	(revision 24025)
@@ -20,4 +20,12 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]