Skip to content

Instantly share code, notes, and snippets.

@jonstorer
Created July 5, 2012 18:46
Show Gist options
  • Save jonstorer/3055613 to your computer and use it in GitHub Desktop.
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
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