module Marshal

Adds two methods named nfreeze and thaw to Marshal module.

@note It is worth mentioning that in spite of its being written using not a

little  knowledge of  both  perl internals  and  ruby internals,  this
library  contains  absolutely  0.00   octets  originates  from  either
projects (as of this writing, at  least).  So it is both perl-free and
ruby-free, in  the sense of  licensing.  You should strictly  stick to
the terms shown at the top of the source code.

@note Also, for future updates of this library, do not copy & paste other

projects,  including  perl  and/or   ruby.   That  should  contaminate
licenses.

Public Class Methods

nfreeze(obj) click to toggle source

Serialize the given object in a way compatible with perl. @param [Object] obj the target object @return [String] a serialized version of obj. @raise [ArgumentError] the obj is not serializable using this method.

Not all kind of objects are serializable. For instance Classes, which are serializable using Marshal.dump, cannot be serialized by this method, because it makes no sense to have a class represented in Perl.

Also for the sake of simple implementation this method pays relatively little attention to make the generated binary smaller. There are cases where more compact expressions is possible. All generated binaries are properly understood by perl though.

# File lib/nfreeze.rb, line 52
def nfreeze obj
   NFREEZE.new.nfreeze obj
end
thaw(obj) click to toggle source

Deserialize perl-generated nfreeze strings into ruby objects. @param [IO, String] obj the source @return [Object] deserialized object @raise [TypeError] the obj is not deserializable

Not all kind of inputs are understood. One big issue is a reference – in perl a [] and a \[] are different, but in ruby you cannot represent such difference.

In practice you would better think this method can understand as far as JSON or YAML or MessagePack or that sort.

# File lib/nfreeze.rb, line 67
def thaw obj
   THAW.new.thaw obj
end