I would have expected the answer for both of the koans below to be
:default_value
but the correct answer is apparently :false_value.
In the first one, I understand the unless statement to mean,
result = :false_value but not if the control statement is false.
Since the control statement is ‘false’ i.e unless false, result should therefore be :default_value. Same thing for the second koan.
Please explain
def test_unless_statement
result = :default_value
unless false
result = :false_value
end
assert_equal __, result
end
def test_unless_statement_modifier
result = :default_value
result = :false_value unless false
assert_equal __, result
end
In both cases, the correct answer is
:false_value. You can think of it this way:unlessmeansif !(...)unless falsemeansif !(false)which meansif trueOr just note that the double negatives cancel each other out.