Problems with Ruby "||" "or"?

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-05-12T03:53:25Z Indexed on 2010/05/12 4:04 UTC
Read the original article Hit count: 226

Filed under:
|

Beginning Ruby Question:

I'm trying to see if a string variable's contents is either "personal" "email" or "password".

I'm trying:

if params[:action] == "password" || "email" || "personal"
  foo
else
  don't foo
end

But that doesn't work and returns strange results, and using IRB to play around with "or" statements I have no idea why the following happens:

irb(main):040:0> a = "email"
=> "email"
irb(main):041:0> a == "password" || "email"
=> "email"
irb(main):042:0> a == "email" || "password"
=> true

I just want something that if any of the 3 variables are true no matter what order they are in it returns true, if not it returns false. Anyone want to help this n00b out?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about beginner