You are viewing a single thread.
View all comments 0 points
*
Ruby:
a || b
(no return
as last line is returned implicitly, no semicolon)
EDIT: As pointed out in the comments, this is not strictly equivalent, as it will return b
if a
is false
as well as if it’s nil
(these are the only two falsy values in Ruby).
0 points
Python:
return a or b
i like it because it reads like a sentence so it somewhat makes sense
and you can make it more comprehensive if you want to:
return a if a is not None else b
0 points
*