From: "Cédric Finance" Date: 2007-01-29T09:11:25+09:00 Subject: Re: Help DRY a couple ifs ------=_Part_56820_25217275.1170029481874 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline You could change it like that: def locate_point(mesh, type, xyz) point = nil if mesh[type].has_key? xyz point = mesh[type][xyz] else $stderr.print "Warning: Did not locate point in #{type} mesh: " $stderr.puts xyz.join(',') end point end ... next unless medium_point = locate_point(mesh,'medium', xyz) next unless fine_point = locate_point(mesh,'fine', xyz) .... Cedric On 1/29/07, Bil Kleb wrote: > > The following snippet is simply nasty, but I > can't see a simple way to DRY it: > > if data['medium'].has_key? xyz > medium = data['medium'][xyz] > else > $stderr.print "Warning: Did not locate point in medium mesh: " > $stderr.puts xyz.join(',') > next > end > if data['fine'].has_key? xyz > fine = data['fine'][xyz] > else > $stderr.print "Warning: Did not locate point in fine mesh: " > $stderr.puts xyz.join(',') > next > end > > I suspect my lack of eval knowledge may be > the trouble, but that may be a good thing? > > Thanks, > -- > Bil Kleb > http://fun3d.larc.nasa.gov > > ------=_Part_56820_25217275.1170029481874--