I am coding something in Ruby where, when a value foois inferred from a method call, I want:
- Returns
fooif footrue - Record the error and return the default if
foofalse.
The easiest naive way to implement this is probably:
foo = procedure(input)
if foo
foo
else
log_error
default
end
but it’s too complicated because it is foorepeated three times, and this style is very necessary.
What is the cleanest, most idiomatic way to write this?
(Performance issues - let's say that foois true in the vast majority of cases.)