2014-11-23
If you want to return a true or false value
in ruby, you could try something like:
if variable
return true
else
return false
endThat’s not very good. In Ruby, we don’t need to explicitly return variables:
if variable
true
else
false
endThis is a bit long-winded. We could try the ternary operator:
variable ? true : falseWe can thin this out even more by using a double negative:
!!variableThis is performing an ‘inverse’ !variable method (which
returns the opposite bool type).