Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active August 29, 2015 14:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trikitrok/63bfb5226f8cc2e8f6c3 to your computer and use it in GitHub Desktop.
Save trikitrok/63bfb5226f8cc2e8f6c3 to your computer and use it in GitHub Desktop.
Unconditional Rock-paper-scissors kata

In this kata we'll use TDD to develop an object-oriented solution for the Rock-paper-scissors game.

The catch is that we can't use any conditionals, that is, if, switch, ternary operator or any other type of conditionals are not allowed.

It's an introductory kata which will help you to hone your OO skills.

This would be the initial code in Ruby:

class RockPaperScissors
  def hand(gesture1, gesture2)
    
  end
end

A hand can have three differente results: either the first gesture wins, the second gesture wins or there's a tie.

As a bonus we'll compare the resulting OO solution with a solution using multimethods.

Spoilers (don't look before trying to do it yourself)

A solution I wrote some time ago in Ruby and a solution using multimethods in Clojure.

Update

A newer solution in Ruby with commits after every passing test and every refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment