From: Rolf Pedersen Date: 2011-02-04T18:04:12+09:00 Subject: Re: Setter method for Hash value --0015175cdab85c81f1049b712aa4 Content-Type: text/plain; charset=ISO-8859-1 Thanks for the input, botp. Your example does the job allright, but designwise, I don't like that the []= method is made available for MyClass itself. However, I'll take whatever works for now! :o) Best regards, Rolf On Fri, Feb 4, 2011 at 4:44 AM, botp wrote: > On Fri, Feb 4, 2011 at 11:22 AM, botp wrote: > > sorry, ignore the previous unclear post.. > > try again, > > class MyClass > def props > some_data = SomeClass::get_prop > self > end > def []=(key,value) > p "i was called" > 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 > "i was called" > #=> 1 > c.props[:b]=2 > "i was called" > #=> 2 > c.props > #=> # > SomeClass::show > #=> {:a=>1, :b=>2} > > > best regards -botp > > --0015175cdab85c81f1049b712aa4--