David,

Thanks, works like a charm.  Replaced eval with module_eval.

Thanks again,

Mike


On Thu, Nov 15, 2001 at 12:03:39PM +0900, David Alan Black wrote:
> Hello --
> 
> On Thu, 15 Nov 2001, Michael Sullivan wrote:
> 
> > Avi,
> >
> > Thanks for getting back to me.  We must be thinking along the same lines
> > because this is what I've come up with:
> >
> > class Module
> >    def attr_callback(*accessors)
> >       accessors.each { |a|
> >          eval "
> >             def #{a}=(p)
> >                @#{a}=p
> >                self.respond_to?(attr_changed, TRUE) && attr_changed( :#{a} )
> >                @#{a}
> >             end
> >
> >             def #{a}
> >                @#{a}
> >             end"
> >          }
> >    end
> > end
> >
> >
> > class TestClass
> >    attr_callback :e
> > end
> >
> > TestClass.instance_methods
> >
> >
> > However, it seems to completely ignore the "eval".  I've replaced the
> > eval with a puts for testing and the methods appear to be formed
> > correctly.  When I go to see if the instance methods are defined, I get
> > an empty array.
> 
> You need module_eval, rather than eval.  With module_eval, the string
> will be eval'd in the context of TestClass, so #e and #e= will become
> instance methods of TestClass.  With eval, #e and #e= will become
> instance methods of Module.
> 
> 
> David
> 
> -- 
> David Alan Black
> home: dblack / candle.superlink.net
> work: blackdav / shu.edu
> Web:  http://pirate.shu.edu/~blackdav
> 
> 

-- 
Michael P. Sullivan                                  
Distributed Computing Systems, LLC                         Cell: 516-429-2080 
E-Mail: mps / discomsys.com                           http://www.discomsys.com/ 
    * UNIX Systems and Database Consulting, Architecture and Management *
"Failing to plan, is planning to fail... plan for the worst, hope for the best"