相关疑难解决方法(0)

自定义to_yaml和domain_type

我需要定义自定义方法来序列化/反序列化对象.我想做类似以下的事情.

class Person
  def to_yaml_type
    "!example.com,2010-11-30/Person"
  end

  def to_yaml
    "string representing person"
  end

  def from_yaml(yaml)
    Person.load_from(yaml)
  end
end
Run Code Online (Sandbox Code Playgroud)

声明序列化/反序列化的正确方法是什么?

ruby yaml

6
推荐指数
2
解决办法
1281
查看次数

标签 统计

ruby ×1

yaml ×1