Should be
If action == "M" or action == "m"

I think you can replace the word or with || if you want.
On Sep 24, 2011 10:54 AM, "Thomas B." <sinixlol / gmail.com> wrote:
> Good afternoon everyone,
>
> I'm a beginner in Ruby with a little bit of experience programming in
> Java and PHP. Right now I'm having a difficult time grasping conditional
> (if/elsif) statements in Ruby. I'm trying to get an if statement to
> evaluate two different strings...i.e.
>
> action = gets.chomp()
>
> if action == "M" || "m"
> menu()
> else
> puts "Please enter in a valid selection."
> end
>
> So, from what I'm used to in programming, the if action == "M" || "m""
> should evaluate to a conditional statement as to whether or not action
> is equal to the strings "M" or "m". However, this does not seem to be
> the case. It's not giving any kind of an error, however, it is calling
> the menu() method regardless of what is entered. I can easily make this
> work by separating the "M" and the "m" into an if and an elsif argument
> i.e:
>
> action = gets.chomp()
>
> if action == "M"
> menu()
>
> elsif action == "m"
> menu()
>
> else
> puts "Please enter in a valid selection."
> end
>
> The above process does seem to work, however, isn't there a simpler way
> of accomplishing this so I'm not adding unnecessary conditional
> statements? I've been trying to find more resources online about
> conditional statements with multiple arguments, but none of them have
> seemed to help out. I'm guessing that my understanding of the || and
> "or" statements is misguided.
>
> Any help would be really appreciated on this issue. Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
>