From: Stefano Crocco Date: 2011-11-16T06:16:20+09:00 Subject: Re: Logical operator || On Wednesday 16 November 2011 06:09:57 Damián M. González wrote: > Ey guys. Look at this: > > a = "mom" > if a == ( "dad" || "mom" ) > puts "Hi" > end > > Very simple. I saw a kind of this exercise in a book that I'm studing( > yes...I'm noob in this ), and I gave it by understood, but now when I'm > practicing i see that...this has not happen. That chunk of code return > me nil...but, judging by the book, that should return me "Hi" right? > Because I say: if a is equal to "dad" or "mom" say "Hi". I don't know if > is my OS( Windows XP SP3( I've had several troubles with it )) or if is > the last version of Ruby, which I am using, the 1.9.3 or what... > I'll appreciate your time guys, thanks. The || operator returns the left operator if it is a true value (everything except nil and false) and the right operand if the left one is a false value. Since "dad" is a true value, that's what || will return. The if expression will be equivalent to: if a == "dad" What you want is: if a == "dad" || a == "mom" I hope this helps Stefano