Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:38:12+00:00 2026-06-14T08:38:12+00:00

I only started looking into the Ruby language two days ago and have quickly

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:38:13+00:00Added an answer on June 14, 2026 at 8:38 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not experienced with sitemaps - only just started looking into them. I have
A couple of days ago I started looking into efficiently drawing bezier curves, and
I just started looking into selenium for automated testing for the past few days
I have just started looking into msbuild, because I want to make my own
I just started looking into jQuery yesterday, before this I programmed in only PHP.
I have recently started looking into MQs and I had some very basic questions,
I've started looking into Entity Framework migrations on 4.3.1. Have a few questions: What's
I am quite new to the Entity Framework, and only have recently started looking
I've only just started looking into jQuery mobile and was going through the Theme
I have started looking into Backbone.js and I seem to be having trouble figuring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.