Skip to content

Instantly share code, notes, and snippets.

@mvoto
Last active May 9, 2017 14:37
Show Gist options
  • Select an option

  • Save mvoto/d314ad904889e9eb9cd1d26b4c4e8c3b to your computer and use it in GitHub Desktop.

Select an option

Save mvoto/d314ad904889e9eb9cd1d26b4c4e8c3b to your computer and use it in GitHub Desktop.

Revisions

  1. mvoto revised this gist May 9, 2017. 1 changed file with 1 addition and 13 deletions.
    14 changes: 1 addition & 13 deletions jokenpokemon.rb
    Original file line number Diff line number Diff line change
    @@ -11,19 +11,7 @@ def wins_against?(other_move)
    send("beats_#{other_move.class.to_s.downcase}?")
    end

    def beats_rock?
    false
    end

    def beats_paper?
    false
    end

    def beats_scissors?
    false
    end

    def method_missing?
    def method_missing(args)
    false
    end
    end
  2. mvoto revised this gist May 9, 2017. 1 changed file with 33 additions and 11 deletions.
    44 changes: 33 additions & 11 deletions jokenpokemon.rb
    Original file line number Diff line number Diff line change
    @@ -2,24 +2,46 @@ class Game
    def self.play(move1, move2)
    return :tie if move1.class == move2.class

    move1.beats?(move2)
    move1.wins_against?(move2)
    end
    end

    class Rock
    def beats?(other_move)
    other_move.is_a?(Scissors)
    class Base
    def wins_against?(other_move)
    send("beats_#{other_move.class.to_s.downcase}?")
    end

    def beats_rock?
    false
    end

    def beats_paper?
    false
    end

    def beats_scissors?
    false
    end

    def method_missing?
    false
    end
    end

    class Rock < Base
    def beats_scissors?
    true
    end
    end

    class Paper
    def beats?(other_move)
    other_move.is_a?(Paper)
    class Paper < Base
    def beats_rock?
    true
    end
    end

    class Scissors
    def beats?(other_move)
    other_move.is_a?(Rock)
    class Scissors < Base
    def beats_paper?
    true
    end
    end
    end
  3. mvoto created this gist May 8, 2017.
    25 changes: 25 additions & 0 deletions jokenpokemon.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    class Game
    def self.play(move1, move2)
    return :tie if move1.class == move2.class

    move1.beats?(move2)
    end
    end

    class Rock
    def beats?(other_move)
    other_move.is_a?(Scissors)
    end
    end

    class Paper
    def beats?(other_move)
    other_move.is_a?(Paper)
    end
    end

    class Scissors
    def beats?(other_move)
    other_move.is_a?(Rock)
    end
    end