I'm coding something in Ruby where, given a value
foo output from a method call, I want to:
- Log an error and return a default value if
The simplest naive way to implement this is probably:
foo = procedure(input) if foo foo else log_error default end
but this feels overly verbose because
foo is repeated three times, and this style is very imperative.
What's the cleanest, most idiomatic way to write this?
(Performance matters-- let's assume that
foo is truthy in the vast majority of cases.)