From: Dave Burt Date: 2005-08-13T11:11:12+09:00 Subject: Re: eval, attr_* like methods Patrick Gundlach asked: > ... 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? You can define your lookup_meth in the target class directly: class Test def self.lookup_meth(*args) #... end lookup_meth :test1, :test2 end Or you can define it in a module, and extend the classes you want to use it in: module LookupMeth def lookup_meth(*args) #... (no changes required here) end end class Test extend LookupMeth lookup_meth :test1, :test2 end > 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'? You can initialize the variable the line before: @othervar ||= nil Or you can change your if condition: if defined?(@otherbar) && @othervar Cheers, Dave