Last active
May 9, 2017 14:37
-
-
Save mvoto/d314ad904889e9eb9cd1d26b4c4e8c3b to your computer and use it in GitHub Desktop.
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 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