From: Marcello Barnaba Date: 2007-02-15T05:02:09+09:00 Subject: Re: Drying a ternary condition Hi, On Wednesday 14 February 2007 19:53, Rob Biedenharn wrote: > The other responders would call klass.down when ARGV[0] is false/ > nil. Also you can't call nil.to_sym (as you probably learned from > ARGV[0].to_sym raising a NoMethodError) or "".to_sym (ArgumentError > for the empty string). yup :) exactly. thanks for pointing this out. > klass.send(Hash.new(:down).merge!({:up=>:up})[(ARGV[0].to_sym � > rescue :up)]) > Yuck! �Stick with the simple ternary for your statement (although you � > might want to use the rescue trick instead of just ||). that's right, with the rescue i'll be sure that even when some not nil? object that doesn't respond_to?(:to_sym) is passed, no exception is being raised. but i'll go with Robert's `case', because it doesn't send to_sym, has just two `up' in a row, and it doesn't use the (heavily abused by myself in the past, i feel guilty) ternary operator. :) -- pub 1024D/8D2787EF 723C 7CA3 3C19 2ACE 6E20 9CC1 9956 EB3C 8D27 87EF