jnicklas/turnip — pull request #86 by bryanchriswhite (2012-12-07 09:30:27+00:00)
Title: Allow Turnip::Table#hashes to be accessed by string or symbol keys

The Problem
=========
We've been wasting time trying to figure out why our tests are failing and it was due to us expecting the Table#hashes to return hashes with symbol keys (which is the convention) and we get nils.

First Attempt
----------
I tried to fix this the first time around by mapping the strings to symbols in the `Table#headers` definition but you didn't like that because if someone had a header in their table like "Foo Bar" it wouldn't map well.

The Solution Now
=============
I created a class called HashWithIndifferentAccess (I know there's a rails class called the same but this is not that) that sets the `default_proc` (which is run when you request from a hash instance a key a that it doesn't contain). This proc first checks to see if the key is a string or a symbol, then to see if there is a key which is of the other respective type in this hash. If there is then it returns that value, if not it returns nil, like usual.

How about that?