2
def get_input(*options)
  puts "Choose one:"
  options.each do |option|
    puts "#{option}"
  end
  choice = gets.chomp.to_s
  options.each do |option|
    if choice.include?(option.to_s)
    return choice
    end
  end
  puts "Command not found..."
  get_input(options)
end

if a user enters an invalid command it puts the available commands again but with the current value including [,]. How would I avoid this.

1
  • Please edit to clarify "current value including [,]. I don't understand what "current value" refers to or what you mean by "including [,]". Commented Oct 25, 2015 at 0:58

1 Answer 1

1

You're missing a splat in the recursive call for get_input:

  puts "Command not found..."
  get_input(options)
end

should be:

  puts "Command not found..."
  get_input(*options)
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.