Am I fundamentally misunderstanding Ruby here? I’ve been writing Ruby code for about 2 years now and just today stumbled on this…
ruby-1.8.7-p249 > i = true and false
=> false
ruby-1.8.7-p249 > i
=> true
Could somebody explain what’s going on here please? I’m sure it’s to spec, but it just seems counter intuitive to me…
The operators
&&andandhave different precedence, and=happens to be in between.The first is read as
(i = true) and false, the second asi = (true && false).