ruby 之 Serializes

ruby的序列化类是 Marshalclass Klass

  def initialize(str)
    @str = str
  end
  def say_hello
    @str
  end
end

o = Klass.new("hello\n")
data = Marshal.dump(o)  将o序列化
obj = Marshal.load(data) 反序列化获得o 
obj.say_hello  #=> "hello\n"

 

你可能感兴趣的:(Serialize)