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

ruby-changes:63290

From: Marc-Andre <ko1@a...>
Date: Wed, 7 Oct 2020 06:12:34 +0900 (JST)
Subject: [ruby-changes:63290] 1486785a57 (master): [lib/ostruct] Fix Marshal loading

https://git.ruby-lang.org/ruby.git/commit/?id=1486785a57

From 1486785a5759c5cb0b7a7bf0bc5368cc9a280191 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Tue, 6 Oct 2020 17:10:46 -0400
Subject: [lib/ostruct] Fix Marshal loading


diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index cc82d59..45ccb54 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -202,10 +202,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L202
   #
   # Provides marshalling support for use by the Marshal library.
   #
-  def marshal_load(x) # :nodoc:
-    x.each_key{|key| new_ostruct_member!(key)}
-    @table = x
-  end
+  alias_method :marshal_load, :update_to_values! # :nodoc:
 
   #
   # Used internally to defined properties on the
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 1e69d79..9d151c3 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -333,4 +333,10 @@ class TC_OpenStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L333
     assert_equal true, os1.eql?(os2)
     assert_equal 300.42, os2.pension
   end
+
+  def test_marshal
+    o = OpenStruct.new(name: "John Smith", age: 70, pension: 300.42)
+    o2 = Marshal.load(Marshal.dump(o))
+    assert_equal o, o2
+  end
 end
-- 
cgit v0.10.2


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

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