vendredi 18 septembre 2020

Why is if (a,b = [nil, nil]) truthy in Ruby?

I'm studying Ruby now, and I don't understand why the test condition

if (a,b = [nil, nil]) # <--
  true
else
  false
end

evaluates as truthy, while

if (a,b = nil) # <--
  true
else
  false
end

is falsy as advertised.

Tested on ruby 2.5 and 2.7 via irb. Added a complete if-else statement for your copy-paste testing.

Aucun commentaire:

Enregistrer un commentaire