From: Robert Klemme Date: 2008-05-02T23:35:04+09:00 Subject: Re: | versus || Any reason for this issue? On 02.05.2008 16:15, Florian Gilcher wrote: > -----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 ||. This is only mostly correct. Semantics of | depend on the class that implements it. irb(main):001:0> %w{a b c} | %w{c d e} => ["a", "b", "c", "d", "e"] irb(main):002:0> %w{a b c} & %w{c d e} => ["c"] Cheers robert