vendredi 28 juillet 2017

Why postfix `if` in Ruby work so strange

I have a follows strange behaviour in Ruby:

2.3.3 :001 > var1.zero? if var1 = 1
NameError: undefined local variable or method `var1' for main:Object

From the other side, if I do same thing in a standard if, all works as expected:

2.3.3 :001 > if var1 = 1
2.3.3 :002?>   var1.zero?
2.3.3 :003?>   end
 => false

Anyone can describe how work postfix if in Ruby?

Aucun commentaire:

Enregistrer un commentaire