rescue nil with ruby

>> 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


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>