From: Rolf Pedersen Date: 2011-02-07T06:23:17+09:00 Subject: Re: Setter method for Hash value --0016368321b2352ca3049ba3b994 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2011/2/4 Jes=FAs Gabriel y Gal=E1n > For the other two, you need a proxy object that can delegate [] and > []=3D to DataClass too. For this to work, MyClass#props needs to wrap > the actual hash returned by DataClass with a wrapper object (Props). > As you need this proxy object to have some hash like behaviour, you > can implement whatever methods you need to behave like a hash. As an > example, apart from [] and []=3D I have implemented inspect and to_s. > > Instead of implementing other methods to make the wrapper object behave mor= e like a Hash object, why not let Props inherit Hash, and just redefine those methods that I need to behave differently? Perhaps like this: class Props < Hash def initialize h replace h end def [](key) ... end def []=3D(key, value) ... end end Best regards, -Rolf --0016368321b2352ca3049ba3b994--