From: Rolf Pedersen Date: 2011-02-04T03:23:27+09:00 Subject: Re: Setter method for Hash value --00163630fdedaf9419049b64d923 Content-Type: text/plain; charset=ISO-8859-1 I see I have forgotten something when extracting code to a more generic example: making an instance of the class... So the corrected version: class MyClass def props some_data = SomeClass::get_prop some_data.to_h end def props[key]=(value) # Not a valid construct SomeClass::set_prop(key, value) end end my_instance = MyClass.new my_instance.props["timeout"] =>"10" my_instance.props["timeout"]="20" => nil -Rolf On Thu, Feb 3, 2011 at 5:09 PM, Rolf Pedersen wrote: > Hi > > I guess there is a simple solution to this, but right now, I can't come up > with it. > > I want to wrap two external functions to behave like a regular hash. > > class MyClass > def props > some_data = SomeClass::get_prop > some_data.to_h > end > def props[key]=(value) # Not a valid construct > SomeClass::set_prop(key, value) > end > end > > props["timeout"] > =>"10" > > props["timeout"]="20" > => nil > > > Now, the getter method works perfectly, but I don't know how to declare the > setter method :o( > > Anyone? > > Kind regards, > Rolf > --00163630fdedaf9419049b64d923--