Created
November 1, 2011 01:42
-
-
Save f440/1329615 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
#!/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