Clean up and speed up ref attribute resolution

For my [schema validation benchmark](https://github.com/treppo/json-schema/blob/benchmarkin/bench/benchmark.rb), this change means a ~10% speedup. I extracted a few methods on the way to clean up.
I don't understand what is now handling unescaping `~0` and `~1` here (see 3c3b897), but I suppose *something* is, as the tests I enabled in that commit are still passing on travis. Do you know how/why this is still working?