From: ara.t.howard@... Date: 2005-12-17T02:29:25+09:00 Subject: Re: Smarter creation of redunant methods On Sat, 17 Dec 2005, Caleb Tennis wrote: > >> you can certainly use metaprogramming here, but you could accomplish the >> same >> effect with far less code: > > My issue is that I've got other methods in the class that use these > particular instance variables, and instead of refactoring all of them in > one fell swoop I'm trying to go in smaller chunks. Mostly because I'm > working on the "production" system (long story), so if break anything I > need to be able to roll it back quickly. then something like class Coil class Error < StandardError; end class << self def coil_attr *list list.flatten.each do |a| module_eval <<-code def #{ a }_coil chan @#{ a }_coil[chan] or raise Error, "chan=\#{ chan }" end code end end end coil_attr %w( a b c x y z ) end hth. -a -- =============================================================================== | ara [dot] t [dot] howard [at] noaa [dot] gov | all happiness comes from the desire for others to be happy. all misery | comes from the desire for oneself to be happy. | -- bodhicaryavatara ===============================================================================