From: botp Date: 2011-02-04T12:22:09+09:00 Subject: Re: Setter method for Hash value On Fri, Feb 4, 2011 at 2:52 AM, Rolf Pedersen wrote: > I'm trying to make getter and setter methods for a virtual hash property > called props. Under the hood, the implementation calls external methods to retrieve or > store the given values for a given key. objects receive methods wc return objects, wc in turn can receive another method, and so fort on the chain.. eg, class MyClass def props some_data = SomeClass::get_prop end def []=(key,value) SomeClass::set_prop(key, value) end end #=> nil class SomeClass class << self @@h={} def get_prop @@h end def set_prop key,value @@h[key]=value end def show @@h end end end #=> nil c=MyClass.new #=> # c.props #=> {} c.props[:a]=1 #=> 1 c.props[:b]=2 #=> 2 c.props #=> {:a=>1, :b=>2} SomeClass::show #=> {:a=>1, :b=>2} best regards -botp