• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

Matching Values

In Ruby, I'm having a problem comparing strings that were input from the keyboard.

example:

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

User enters "test," minus quote marks.

The output should be:

false

I want to get a "true" because the entered value is the same as the stored value. How do I do this?
0
JCW2
Asked:
JCW2
  • 2
1 Solution
 
JCW2Author Commented:
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 = Array.new(0)
input = gets()

while((input =~ /^leave$/) != 0  &&
      (input =~ /^quit$/) != 0 )

    # puts input.eql?(quit)
    if((input =~ /^\d+$/) == 0)
        arraylist.push(input.to_i)
    elsif((input =~ /^leave$/) == 0  ||
          (input =~ /^quit$/) == 0      )
        # break
    else
        puts "Please enter a valid integer, or enter either quit or leave."
    end
    input = gets()
end

Open in new window

0
 
JCW2Author Commented:
As far as I know this is the proper solution.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now