Posts Tagged ‘smelly’
rescue nil with ruby
November 5th, 2007 •
tags: idioms, irb, ruby, smelly
>> bar = nil
=> nil
>> { :foo => bar ? bar.baz : nil }
=> {:foo=>nil}
# vs.
>> { :foo => (nil.bla rescue nil) }
=> {:foo=>nil}
# does rescue nil win in terms of readability?
# It can be argued, that exception handling
# is not the right way to process this kind logic,
# since it is not always exceptional behaviour
# that motivates the use of rescue nil