From: Daniel N Date: 2007-01-29T09:59:50+09:00 Subject: Re: Help DRY a couple ifs ------=_Part_48685_20626922.1170032387431 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 1/29/07, Bil Kleb wrote: > > Andy Lester wrote: > > > > Create an outer loop that has "fine" and "medium", and plug that in to > > your if blocks. > > Sure, but how do you get medium and fine as variable names. > :) > > If you can afford them to become instance variables use instance_variable_set( symbol, object ) Then your method can become xyz =3D a key [:medium, :fine].each do |type| if data[type].has_key? xyz instance_variable_set( "@#{type}".to_sym, data[type] ) else @stderr.print "Warning: Did not locate point in #{type} mesh: " @stderr.puts xyz.join( ',' ) end end But I do like C=E9dric's response better. ------=_Part_48685_20626922.1170032387431--