Tag: 二进制序列化

在Ruby中使用Marshal :: dump进行对象序列化时如何写入文件

假设我有类Line的对象行 : class Line def initialize point1, point2 @p1 = point1 @p2 = point2 end end line = Line.new … 如何对行对象进行二进制序列化? 我尝试过: data = Marshal::dump(line, “path/to/still/unexisting/file”) 但它创建了文件,并没有添加任何东西。 我读了Class:IO文档,但我无法真正理解它。