8000 [Fixes #19] Fix Marshal loading · djberube/ruby@014844a · GitHub
[go: up one dir, main page]

Skip to content

Commit 014844a

Browse files
committed
[Fixes ruby#19] Fix Marshal loading
1 parent 784d3cb commit 014844a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/ostruct.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ def marshal_dump # :nodoc:
212212
#
213213
# Provides marshalling support for use by the Marshal library.
214214
#
215-
def marshal_load(x) # :nodoc:
216-
x.each_key{|key| new_ostruct_member!(key)}
217-
@table = x
218-
end
215+
alias_method :marshal_load, :update_to_values! # :nodoc:
219216

220217
#
221218
# Used internally to defined properties on the

test/ostruct/test_ostruct.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,10 @@ def test_yaml
327327
assert_equal true, os1.eql?(os2)
328328
assert_equal 300.42, os2.pension
329329
end
330+
331+
def test_marshal
332+
o = OpenStruct.new(name: "John Smith", age: 70, pension: 300.42)
333+
o2 = Marshal.load(Marshal.dump(o))
334+
assert_equal o, o2
335+
end
330336
end

0 commit comments

Comments
 (0)
0