From: Florian Gilcher Date: 2008-05-02T23:15:30+09:00 Subject: Re: | versus || Any reason for this issue? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On May 2, 2008, at 4:01 PM, Iņaki Baz Castillo wrote: > Hi, why in the second case the non declared "my_var" variable is > processed but not in the first case? > > irb> nil || 2 || my_var > => 2 > > irb> nil | 2 | my_var > NameError: undefined local variable or method `my_var' > > > Of course, I prefer the first case: 2 is already true so there is no > reason to read the next "my_var". Also, it's not good for performance, > is it? | is the bitwise OR and something entirely different from ||. | needs to evaluate both Operands while the value of a logical OR (||) is known at the moment that one of the Operands is true. Regards Florian Gilcher -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkgbIfUACgkQJA/zY0IIRZakmwCgwtL5xfsC/Z8FRNYN6QaJQn0I FUQAn39NRwifvYwfJcVurDBzJ1/mzH0i =SLZS -----END PGP SIGNATURE-----