views:

24

answers:

1

I've got a Hash with a default proc that I'd like to to Marshal to a file, but the default proc prevents me from doing that.

Rather than writing my own _dump and _load methods, is it possible instead to remove the default_proc instead? At the point where I'm Marshalling I'm never going to need the default_proc again.

+2  A: 

Just reset the default:

h.default = nil

More explicitely:

def dumpable_hash(h)
  return h unless h.default_proc
  h = h.clone  # clear the default_proc
  h.default = nil
end      
Marc-André Lafortune
Turns out `h.default = nil` clears the default proc -- that's all I needed. Thanks!
Stewart Johnson