Q: How to compare strings against command prompt input in Ruby I only started looking into the Ruby language two days ago and have quickly learned that I am far too constrained into the mindset of C derived languages... I am trying to do the comparison on strings as such:
def menu_listen
    action = gets
    while !(action.eql?("up")) && !(action.eql?("down")) && !(action.eql?("close")) do
        puts "'#{action}' is not a valid command at this time."
        action = gets
    end
    return action
end

...which was earlier written as such:
def main_listen
    action = gets
    while action != "up" && action != "down" && action != "close" do
        puts "'#{action}' is not a valid command at this time."
        action = gets
    end
    return action
end

I read on this site that thisString.eql?(thatString) is the same as thisString == thatString, it would seem so because neither work. Any input I type into the command prompt does not get past the while loop and gives me this in response:
'down
' is not a valid command at this time.

So does this mean that the press of the enter key is also stored as a new line on the command prompt input? Can anyone tell me how to implement this so that the string comparison works properly?

A: gets takes in the eol character as well, so use gets.chomp to only take in the actual string. The chomp method removes your carriage returns as well as your newlines.
As far as the string comparison goes, it's a little more ruby like to just compare whether or not your input exists in an array of predefined strings instead of chaining && and eql?, for example:
while not %w(up down close).include? action do

This is cleaner than the chaining, and makes it easier to modify too.

A: def menu_listen
  until r = (['up', 'down', 'close'] & [t = gets.strip]).first 
    puts "#{t} is not a valid command"
  end
  r
end


A: All you need is a String#chomp method, which removes the separator from the end of the string.
    def menu_listen
      while 1 do
        action = gets.chomp
        return action if %w(down up close).include? action.downcase
        puts "#{action}' is not a valid command at this time."
      end
    end

