views:

251

answers:

2

I'm serialising some object using YAML::dump(). Unfortunately that includes some elements that shouldn't be serialised, like locks with waiting threads sometimes.

Is there any way to exclude selected types from serialisation, or force them to be serialised as an empty object instead?

A: 

It doesn't sound very elegant to me, but you could extend those objects to dump as nil

class IgnoredObject
  def to_yaml
    nil
  end
end
Jorge Bernal
`to_yaml': wrong number of arguments (1 for 0) (ArgumentError); then after fixing that -- `emit': wrong argument type nil (expected Data) (TypeError)
viraptor
A: 

Solved with:

class ClassToNil
  def to_yaml
    nil.to_yaml
  end
end
viraptor