Created
February 21, 2014 21:46
-
-
Save wannabefro/9144171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
VALID_INPUT = [1,2,3,4] | |
@products = [] | |
def get_choice | |
puts 'Enter your selection' | |
choice = gets.chomp.to_i | |
validate_choice(choice) | |
scan(choice) | |
end | |
def validate_choice(choice) | |
if !VALID_INPUT.include?(choice) | |
puts 'I hate you' | |
get_choice | |
end | |
end | |
def scan(choice) | |
if finished?(choice) | |
puts @products | |
else | |
@products << choice | |
get_choice | |
end | |
end | |
def finished?(choice) | |
choice == 4 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment