I am coding something in Ruby where, when a value foo
is inferred from a method call, I want:
- Returns
foo
if foo
true - Record the error and return the default if
foo
false.
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 foo
repeated three times, and this style is very necessary.
What is the cleanest, most idiomatic way to write this?
(Performance issues - let's say that foo
is true in the vast majority of cases.)