Module: Marshal

Defined in:
marshal.c

Constant Summary collapse

MAJOR_VERSION =
INT2FIX(MARSHAL_MAJOR)
MINOR_VERSION =
INT2FIX(MARSHAL_MINOR)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dump(obj[, anIO], limit = --1) ⇒ Object

Serializes obj and all descendent objects. If anIO is specified, the serialized data will be written to it, otherwise the data will be returned as a String. If limit is specified, the traversal of subobjects will be limited to that depth. If limit is negative, no checking of depth will be performed.

class Klass
  def initialize(str)
    @str = str
  end
  def sayHello
    @str
  end
end

(produces no output)

o = Klass.new("hello\n")
data = Marshal.dump(o)
obj = Marshal.load(data)
obj.sayHello   #=> "hello\n"


727
728
729
# File 'marshal.c', line 727

static VALUE
marshal_dump(argc, argv)
int argc;

.load(source[, proc]) ⇒ Object .restore(source[, proc]) ⇒ Object

Returns the result of converting the serialized data in source into a Ruby object (possibly with associated subordinate objects). source may be either an instance of IO or an object that responds to to_str. If proc is specified, it will be passed each object as it is deserialized.

Overloads:



1385
1386
1387
# File 'marshal.c', line 1385

static VALUE
marshal_load(argc, argv)
int argc;

.load(source[, proc]) ⇒ Object .restore(source[, proc]) ⇒ Object

Returns the result of converting the serialized data in source into a Ruby object (possibly with associated subordinate objects). source may be either an instance of IO or an object that responds to to_str. If proc is specified, it will be passed each object as it is deserialized.

Overloads:



1385
1386
1387
# File 'marshal.c', line 1385

static VALUE
marshal_load(argc, argv)
int argc;

Instance Method Details

#dump(obj[, anIO], limit = --1) ⇒ Object (private)

Serializes obj and all descendent objects. If anIO is specified, the serialized data will be written to it, otherwise the data will be returned as a String. If limit is specified, the traversal of subobjects will be limited to that depth. If limit is negative, no checking of depth will be performed.

class Klass
  def initialize(str)
    @str = str
  end
  def sayHello
    @str
  end
end

(produces no output)

o = Klass.new("hello\n")
data = Marshal.dump(o)
obj = Marshal.load(data)
obj.sayHello   #=> "hello\n"


727
728
729
# File 'marshal.c', line 727

static VALUE
marshal_dump(argc, argv)
int argc;

#load(source[, proc]) ⇒ Object (private) #restore(source[, proc]) ⇒ Object (private)

Returns the result of converting the serialized data in source into a Ruby object (possibly with associated subordinate objects). source may be either an instance of IO or an object that responds to to_str. If proc is specified, it will be passed each object as it is deserialized.

Overloads:



1385
1386
1387
# File 'marshal.c', line 1385

static VALUE
marshal_load(argc, argv)
int argc;

#load(source[, proc]) ⇒ Object (private) #restore(source[, proc]) ⇒ Object (private)

Returns the result of converting the serialized data in source into a Ruby object (possibly with associated subordinate objects). source may be either an instance of IO or an object that responds to to_str. If proc is specified, it will be passed each object as it is deserialized.

Overloads:



1385
1386
1387
# File 'marshal.c', line 1385

static VALUE
marshal_load(argc, argv)
int argc;