Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用YAML::dump(). 不幸的是,这包括一些不应该被序列化的元素,比如有时带有等待线程的锁。
YAML::dump()
有没有办法从序列化中排除选定的类型,或者强制将它们序列化为空对象?
解决了:
class ClassToNil def to_yaml nil.to_yaml end end
对我来说这听起来不是很优雅,但是您可以将这些对象扩展为转储为 nil
class IgnoredObject def to_yaml nil end end