Skip to content

Instantly share code, notes, and snippets.

@mvoto
Last active May 9, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvoto/d314ad904889e9eb9cd1d26b4c4e8c3b to your computer and use it in GitHub Desktop.
Save mvoto/d314ad904889e9eb9cd1d26b4c4e8c3b to your computer and use it in GitHub Desktop.
class Game
def self.play(move1, move2)
return :tie if move1.class == move2.class
move1.wins_against?(move2)
end
end
class Base
def wins_against?(other_move)
send("beats_#{other_move.class.to_s.downcase}?")
end
def method_missing(args)
false
end
end
class Rock < Base
def beats_scissors?
true
end
end
class Paper < Base
def beats_rock?
true
end
end
class Scissors < Base
def beats_paper?
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment