From: Devin Mullins Date: 2007-02-15T14:22:55+09:00 Subject: Re: Drying a ternary condition Marcello Barnaba wrote: > How would you write the following statement: > 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] }) Devin