mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[lib/ostruct] Fix Marshal loading
This commit is contained in:
parent
260322fbc5
commit
1486785a57
2 changed files with 7 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue