Skip to content

Instantly share code, notes, and snippets.

@f440
Created November 1, 2011 01:42
Show Gist options
  • Save f440/1329615 to your computer and use it in GitHub Desktop.
Save f440/1329615 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
CHOICE = ["rock", "paper", "scissors"]
def main(argv)
unless argv.length == 2
abort "#{$0} [Left choice] [Right choice]"
end
(left, right) = argv
if left == "rock"
case right
when "rock"
puts "Draw."
when "paper"
puts "Right win."
when "scissors"
puts "Left win."
else
abort "1st argument must be #{CHOICE.join(' or ')}"
end
elsif left == "paper"
case right
when "rock"
puts "Left win."
when "paper"
puts "Draw."
when "scissors"
puts "Right win."
else
abort "1st argument must be #{CHOICE.join(' or ')}"
end
elsif left == "scissors"
case right
when "rock"
puts "Right win."
when "paper"
puts "Left win."
when "scissors"
puts "Draw."
else
abort "1st argument must be #{CHOICE.join(' or ')}"
end
end
end
if __FILE__ == $0
main(ARGV)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment