Matching Values

Posted on 2011-04-22
Last Modified: 2012-08-13
In Ruby, I'm having a problem comparing strings that were input from the keyboard.


input = gets.to_s
test = "test"
puts "#{input.eql?(test)}"

User enters "test," minus quote marks.

The output should be:


I want to get a "true" because the entered value is the same as the stored value. How do I do this?
Question by:JCW2

    Accepted Solution

    Response to my own question:
    # To change this template, choose Tools | Templates
    # and open the template in the editor.
    puts "Input: A list of numbers from the keyboard."
    puts "Output: The second-smallest number in the list, along with its position
          in the list, with 1 being the position of the first number."
    arraylist =
    input = gets()
    while((input =~ /^leave$/) != 0  &&
          (input =~ /^quit$/) != 0 )
        # puts input.eql?(quit)
        if((input =~ /^\d+$/) == 0)
        elsif((input =~ /^leave$/) == 0  ||
              (input =~ /^quit$/) == 0      )
            # break
            puts "Please enter a valid integer, or enter either quit or leave."
        input = gets()

    Open in new window


    Author Closing Comment

    As far as I know this is the proper solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now