3 # load(source, proc = nil, freeze: false) -> obj
4 # restore(source, proc = nil, freeze: false) -> obj
6 # Returns the result of converting the serialized data in source into a
7 # Ruby object (possibly with associated subordinate objects). source
8 # may be either an instance of IO or an object that responds to
9 # to_str. If proc is specified, each object will be passed to the proc, as the object
10 # is being deserialized.
12 # Never pass untrusted data (including user supplied input) to this method.
13 # Please see the overview for further details.
15 # If the <tt>freeze: true</tt> argument is passed, deserialized object would
16 # be deeply frozen. Note that it may lead to more efficient memory usage due to
17 # frozen strings deduplication:
19 # serialized = Marshal.dump(['value1', 'value2', 'value1', 'value2'])
21 # deserialized = Marshal.load(serialized)
22 # deserialized.map(&:frozen?)
23 # # => [false, false, false, false]
24 # deserialized.map(&:object_id)
25 # # => [1023900, 1023920, 1023940, 1023960] -- 4 different objects
27 # deserialized = Marshal.load(serialized, freeze: true)
28 # deserialized.map(&:frozen?)
29 # # => [true, true, true, true]
30 # deserialized.map(&:object_id)
31 # # => [1039360, 1039380, 1039360, 1039380] -- only 2 different objects, object_ids repeating
33 def self.load(source, proc = nil, freeze: false)
34 Primitive.marshal_load(source, proc, freeze)