Refactoring a Hash to a Hashie::Mash
This afternoon I wanted to do a little refactoring on the codebase for the project I'm working on. Right now, one of the two main classes we're using in the code is real just a ruby Hashes, and while that's great for loading and persistence, it's not really where we would like to be, and there's a decent Open Source gem called Hashie. This guy is really just methods on top of Hash that allow you to use the "dotted notation" as opposed to the "bracket notation":
# the old way: a = merchant["name"] # the Hashie::Mash way: a = merchant.name
This makes the code look a lot simpler - though it doesn't really make it any better. However, it adds nice convenience methods as well:
a.name = nil a.name? # => false
The real goal is to move a lot of the methods that take a single argument - the Demand, and looks into it for some bit of information, and make them methods on the Demand so that it's a lot clearer where the business logic is being held.
There were a lot of little complications - primarily because of the fact that Ruby devs hate writing comments, and so the code is the comments, and I had to do quite a bit of digging to know how to handle an initialize method on a subclass of Hashie::Mash. Ugh… I do wish they'd learn to comment things.
I got a lot of work done, but not enough to call it a day, so I moved it all into a branch and I'll work on it more tomorrow.