[ruby/etc] bump up to 1.3.1
[ruby-80x24.org.git] / marshal.rb
blob9ff74dd8b248cc19f507767466adb637d2acb024
1 module Marshal
2   # call-seq:
3   #    load(source, proc = nil, freeze: false) -> obj
4   #    restore(source, proc = nil, freeze: false) -> obj
5   #
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.
11   #
12   # Never pass untrusted data (including user supplied input) to this method.
13   # Please see the overview for further details.
14   #
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:
18   #
19   #    serialized = Marshal.dump(['value1', 'value2', 'value1', 'value2'])
20   #
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
26   #
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
32   #
33   def self.load(source, proc = nil, freeze: false)
34     Primitive.marshal_load(source, proc, freeze)
35   end
37   class << self
38     alias restore load
39   end
40 end