Created
July 5, 2012 18:46
-
-
Save jonstorer/3055613 to your computer and use it in GitHub Desktop.
Small script to help rank the values in an array from user input
This file contains hidden or 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
class Array | |
CHOOSE_OPTIONS = {'a' => -1, 'b' => 1, 'c' => 0} | |
def choose | |
self.sort! do |x, y| | |
answered = false | |
begin | |
puts "Which do you prefer?" | |
puts " (A) #{x}" | |
puts " (B) #{y}" | |
puts " (C) Neither" | |
response = gets.strip.downcase | |
if CHOOSE_OPTIONS.has_key?(response) | |
answered = true | |
else | |
puts "#{response} isn't an option" | |
end | |
end until answered | |
Integer(CHOOSE_OPTIONS[response]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment