From: Robert Klemme Date: 2005-04-04T15:14:42+09:00 Subject: Re: [EVALUATION] - E03 - jamLang Evaluation Case Applied to Ruby "Saynatkari" schrieb im Newsbeitrag news:8yz1QGr1.1112552007.2231070.ruerue@bidwell.textdrive.com... > > Le 3/4/2005, "Ilias Lazaridis" a �crit: >>Saynatkari wrote: >>> Le 3/4/2005, "Ilias Lazaridis" a �crit: >>>>Csaba Henk wrote: >>>>>On 2005-04-03, Ilias Lazaridis wrote: >>[...] >> >>>>>>but it gives me the basic idea: >>>>>> >>>>>>class Object >>>>>> def meta() @meta ||= {} end >>>>>>end >>>>>> >>>>>>talker.sayYourName.meta[:author] = "it's just me" >>>>>>puts talker.sayYourName.meta[:author] >>>>>>=> it's just me >>>>> >>>>>If you want metadata for the _function_, then it's not exactly the way >>>>>to go. >>>>> >>>>>The sayYourName method, as defined above, is a side-effecting one, >>>>>writes out @name, then returns nil, which is a unique object, without >>>>>any reference to talker. That is, it's not a possible carrier of >>>>>metainformation. >>[...] >> >>>>I like the extracted construct - and it works in practice. >>[...] >> >>> Just to make sure there is no confusion: >>> >>> talker.sayYourName.meta[:author] = "it's just me" >>> >>> sayYourName, when evaluated, returns nil. >> >>This behaviour seems non logical. >> >>talker.sayYourName.meta >> >>talker_object->sayYourName_object->meta_object >>Class object Method object Hash object >> >>The sayYourName Method Object is not executed, it's just a part of the >>nested datastructure. > > You are not accessing the method, you are _calling_ the method. > As mentioned earlier, talker.method(:sayYourName).meta would > work. No, it doesn't. Method instances are not suited to carrying meta data: >> class Foo; def bar() end end => nil >> Foo.new.method(:bar).meta[:test]="I'm here" => "I'm here" >> f=Foo.new => # >> f.method(:bar).meta[:test]="I'm here" => "I'm here" >> f.method(:bar).meta[:test] => nil The reason is that Method instances are created on each request: >> f.method(:bar).__id__ => 134967116 >> f.method(:bar).__id__ => 134950544 >> f.method(:bar).__id__ => 134664456 >> f.method(:bar).__id__ => 134636916 You have to stick to the class or object as point where meta data is stored. If you want to store a hash per method you can do class Object def meta() @meta ||= Hash.new{|h,k| h[k]={}} end end >> f=Foo.new => # >> f.meta[:bar][:info]="test" => "test" >> f.meta[:bar] => {:info=>"test"} >> f.meta[:bar][:info] => "test" Kind regards robert