Apologies in advance if you already understand this distinction, but
it is one that has tripped many a programmer, even those who should
know betterIf you indeed mean to assign the value to ‘a’ (as in
the first example), you can probably avoid the warning from Ruby by
breaking this into two lines, e.g.a = 1 if a then true else false end
I did understand the distinction, I was just puzzled that Ruby would
throw a warning on something that worked as intended and as advertised
although it would probably be considered ambigious.
But in this real-life example, it doesn’t that seem ambigious (and
hence useful):
def apply_coupon(code)
if @coupon = Coupon.find_by_code(code) then true else false end
end
I guess I’m questioning when, or even if, the parser should throw
warnings on something that it considers to be bad style.
/ David