3 ms·
Only when working with explicit Booleans, yes. Otherwise no: [21] pry(main)> foo = 1 => 1 [22] pry(main)> bar = false => false [23] pry(mai
by Slackwise 14y ago
Only when working with explicit Booleans, yes. Otherwise no:
[21] pry(main)> foo = 1
=> 1
[22] pry(main)> bar = false
=> false
[23] pry(main)> foo && !bar
=> true
[24] pry(main)> foo &! bar
TypeError: can't convert true into Integer
from (pry):24:in `&'
In this case, the behavior is inappropriate in that Ruby evaluates only false and nil for False, and everything else as True.
I'm going to assume this is some quirk or "feature" as part of the bitwise operator '&'.