serialization - Modify an object before marshaling it in Ruby -


i have object containing sensitive data want marshal (using marshal) without sensitive data.

i'd able say:

def _dump(*args)   # clean-up sensitive data   super end 

but produces 'no superclass method' error. there way can make object behave way want in response marshal.dump, while using default implementation?

i want marshal.dump(my_obj) work out-of-the-box without requiring api consumer remember call different method.

it may there no superclass method _dump. if it's defined on object it's called. if not, default handler used.

you want clone object , remove sensitive fields, returning hash inside _dump function, undo within _load method.

you can read the documentation on marshal describes recommended methods.


Comments