My method uses a variable length argument list, and I would like to like to check each variable using an if-else statement. Is this possible? I'm unsure if my syntax is correct.
def buy_choice(*choice)
loop do
input = gets.chomp
if input == choice
puts "You purchased #{choice}."
break
else
puts "Input '#{input}' was not a valid choice."
end
end
end
So if I use buy_choice("sailboat", "motorboat")
, an input
of either "sailboat"
or "motorboat"
should be successful.