thoughtbot/sudoku_validator — pull request #8 by danscotton (2013-12-10 01:20:48+00:00)
Title: Outside-In with Aruba/RSpec for SudokuValidator Example

I really enjoyed this exercise! Super fun!

I've been reading up a lot on domain modelling and value objects recently, and so my design is heavily influenced by those ideas. I've also been meaning to test out aruba for a while – great little gem!

**Design**
- `FileParser` converts `*.sudoko` files into a simple array format that `Puzzle` can use.
- `Puzzle` is made up of `Row`, `Column` and `Box` value objects. They all implement the `Unit` interface (having looked up *Sudoku* on wikipedia, a *Unit* is the common term for all of these).
- I ended up using `Matrix` in my implementation, and quite liked the interface for `Vector` when stumbling across it... so I can instantiate objects like `Row[1, 2, ..., 9]` etc.
- `Puzzle` is aware of its own validity and completeness (wasn't too sure about whether this was a Puzzle's responsibility at first, but this is how it ended up. What do you think?)
- `Validator` takes a `Puzzle` and can be sent `:status` and `:errors` that can be output back onto the command line. (Unsure as to whether *Validator* is the right name for this object as it doesn't actually do the validating. Couldn't think of an alternative though...ideas?)

**Some things I was mindful of throughout the exercise:**
- Sudoku is not zero-indexed, only programming languages are. I wanted to avoid (n+1) bits and pieces everywhere, so most methods return hashes indexed at 1, instead of arrays. Unnecessary?
- I didn't want to couple my solution to being a 'only works on the command-line' app. *What if we wanted to make this available in a web app, etc.?* Same deal with how `Puzzle` receives its input.
- I used Numbers instead of Strings for the sudoku numbers. Made sense to me, especially when rules such as *all numbers add up to 45* exist in sudoku.

**Some things I'm not so sure about**
- The whole *value object* thing. Think I might've implemented a load of unnecessary `:==` and `:hash` gumpf.

Would love to hear your feedback, and I'll be checking out some of the other solutions on here too. These exercises are great – keep them coming!