Protecting internal table

The OpenStruct class stores values in an internal hash @table. For use
with Marshal, it exposes this table via the method:

def marshal_dump
  @table
end

Seems to me that this exposure should be protected to prevent people
from
modifying it in place, particularly adding non-symbol keys.

But what is the proper way of doing this? Should the result be frozen?
Perhaps #dup? Or both? Or am I being over concerned and we shouldn’t
bother?

Intransition писал 21.02.2012 07:46:

modifying it in place, particularly adding non-symbol keys.

But what is the proper way of doing this? Should the result be
frozen?
Perhaps #dup? Or both? Or am I being over concerned and we shouldn’t
bother?

If the person is motivated enough to discover this method, s/he will
also be
motivated enough to use `open_struct.send(:instance_variable_get,
:@table)’.
There is no way you can prevent something like this to happen in Ruby.