From: Marcello Barnaba Date: 2007-02-15T14:33:09+09:00 Subject: Re: Drying a ternary condition Hi, On Thursday 15 February 2007 06:22, Devin Mullins wrote: > Marcello Barnaba wrote: > > klass.send((ARGV[0] || :up).to_sym == :up ? :up : :down) > klass.send(%w{up down}.find(:up) {|dir| dir == ARGV[0]}) > > The only way I can think of to get rid of the second 'up' is to > introduce an abstraction. It provides an additional piece of information > -- which one's the default. So: > dirs = %w{up down} > klass.send(dirs.find(dirs.first) {|dir| dir == ARGV[0] }) clever use of .first (setting the default) and .find. but I think that readability hit a regression.. and first we stood in front of 3 ups, now we stand in front of 4 dirs! :) -- pub 1024D/8D2787EF 723C 7CA3 3C19 2ACE 6E20 9CC1 9956 EB3C 8D27 87EF