diff options
-rw-r--r-- | lib/ostruct.rb | 5 | ||||
-rw-r--r-- | test/ostruct/test_ostruct.rb | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index cc82d59e76..45ccb54925 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -202,10 +202,7 @@ class OpenStruct # # 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 1e69d79dfd..9d151c3a2f 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -333,4 +333,10 @@ class TC_OpenStruct < Test::Unit::TestCase 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 |