From: Patrick Gundlach Date: 2005-08-13T02:06:11+09:00 Subject: Re: eval, attr_* like methods Hello Brian, > class Object > def self.lookup_meth(*args) > args.each do | name | > eval %( > def #{name} > @#{name} ||= '24' > end > > def #{name}=(arg) > @#{name} = arg > end > ) > end > end > end > > class Test > lookup_meth :test1, :test2 > > def testme > p self.test1 > self.test1 = 42 > p self.test1 > end > end > > Test.new.testme > => > "24" > 42 > Hope that helps, Yes, it helps! But there are two more questions left: since this lookup_meth is defined in Ojbect, it might get overridden by another method definition of the same name, right? Is it possible to move this definition somewhere 'closer' to my classes? And number two: I have one variable that I need to check. Example: def self.lookup_meth(*args) args.each do | name | eval %( def #{name} if @othervar # <----------- puts "hello" end @#{name} ||= '24' end Any way to avoid a warning about 'instance variable @othervar not initialized'? Thanks so far, Patrick