i = true and false in Ruby is true?

后端 未结 5 962
傲寒
傲寒 2021-01-04 05:55

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 =         


        
5条回答
  •  悲&欢浪女
    2021-01-04 06:06

    Your line is parsed as

    i = true and false
    (i = true) and false
    true and false
    

    And of course because of i = true, i will be true afterwards.

提交回复
热议问题