From: William James Date: 2007-01-29T14:30:09+09:00 Subject: Re: Help DRY a couple ifs On Jan 28, 5:27 pm, 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 Klebhttp://fun3d.larc.nasa.gov If the hash isn't autovivifying (if refering to a non-existant entry won't create an entry): medium = data['medium'][xyz] or ( $stderr.print "Warning: Did not locate point in medium mesh: " $stderr.puts xyz.join(',') next )