def foo(x)
puts "#{x} > 10" and return if x > 10
puts "#{x} <= 10"
end
On the console:
> foo(3)
3 <= 10
> foo(30)
30 > 10
30 <= 10
CodePudding user response:
Kernel#puts
returns nil
, which is falsey. and
and &&
only evaluate their right operand if they need to; since the left operand is already falsey, there is no need to evaluate the right operand.