From: Robert Klemme Date: 2004-02-27T17:44:52+09:00 Subject: Re: Callback "Han Holl" schrieb im Newsbeitrag news:b93fa83f.0402260928.25ffbd4a@posting.google.com... > Hi, > > The following code works, but I was wondering if the creation of the @obj > instance variable is really necessary? It is not. I'd consider it harmful since you will have problems defining more than one callback this way. Solutions that others have proposed are far betters since they store 'obj' in a closure. So you can invoke #callback arbitrarily often. I wonder though what you are trying to achieve. It looks quite complicated to me and currently I don't have a clue about the real world problem you are trying to solve. Regards robert > class A > def callback(name, obj) > @obj = obj > eval("def #{name}; @obj.keys; end") > end > end > > class B > attr_reader :keys > def initialize(k, cb) > @keys = k > cb.callback('cassette', self) > end > end > > a = A.new > g = B.new([1,2,3], a) > puts a.cassette