From: han.holl@... (Han Holl) Date: 2004-02-27T18:04:47+09:00 Subject: Re: Callback ts wrote in message news:<200402261738.i1QHcl815264@moulon.inra.fr>... > >>>>> "H" == Han Holl writes: > > H> The following code works, but I was wondering if the creation of the @obj > H> instance variable is really necessary? > > The problem is not with the instance variable, but with the evil eval :-) > > You don't prefer this ? > > svg% cat b.rb > #!/usr/bin/ruby > class A > end > > class B > def initialize(k, cb) > class << cb; self end.instance_eval do > define_method('cassette') { k } > end > end > end > a = A.new > g = B.new([1,2,3], a) > puts a.cassette > svg% > > svg% b.rb > 1 > 2 > 3 > svg% > Oh, yes. I prefer that _very_ much. But is instance_eval not also an 'evil eval' ? And define_method isn't in my Pickaxe, nor in ri-0.8a-1, nor in the doc directory of ruby-1.8.0 not in the ChangeLog. It _does_ appear in doc/Changelog-1.8.0 of ruby-1.8.1. Strange. And I kind of wonder about the 'class << cb; self end.' construction. Wouldn't 'cb.class.' achieve the same ? Both 'b.class.class' and 'class << b; self end.class' return Class in irb. Many thanks to you, and to Gregory and Pit, for the helpful reactions.