def a
return unless false || false || true
return "HELLO FROM METHOD"
end
OR Equivalent
def a
return if true && true && false
return "HELLO FROM METHOD"
end
Output on calling method :a
HELLO FROM METHOD
2.
def b
unless false || false || true
return "HELLO FROM METHOD"
end
end
Output on calling method :b
nil
We have this 2 code blocks
- method :a where unless is cobined with return inside the method.
- method :b where unless block itself is there inside the method.
I’m a bit confused that how method :a returned the string as the resultant of the unless in both the methods would be like unless true
or if false
then whats going on in the method :a
Is it like whenever we combine the return with if or unless it considered as a whole and its evaluated as a whole only, if yes then its kind of makes sense
sorry I am unable to explain this “evaluated as a whole” but is it like it cosiders return if false
or return unless true
as whole statement?
Shyam N Sagothia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.