August 26, 2015 Log No. 382

Reinventing the Wheel…

…using a wheel. Ha.

After the longest assessment we’ve ever had (2 hours!) this morning, we continued on to RailsLite, aka our introduction to handling server requests/responses. All I can say is that after just 1 day of it, I’m glad the Rails guys blazed that trail for me, haha. Even with several layers of abstraction built in already (Ruby, WEBrick, and some of the Rails functions), things that seemed simple before suddenly required serious thought. For example, parsing parameter hashes. Sure, the straightforward params[key] = value pairing was simple enough, but once you add in multiple layers of nesting ( params[key1][key2].[key_x] = value ), how to construct the proper nested hash?

I ended up doing it recursively (now when I think nests, I think recursion–slowly coming around to it, after nearly a decade of hating the subject). Then I ran into the unexpected byproduct problem of how to properly merge my params key/value pairs together: Ruby’s merge! method only looks at the top-level hash keys, which led to nested stuff overwriting each other just because they shared the same top-level key. Thankfully Rails (yes, Rails to the rescue–those guys are doing God’s work) provides a deep_merge! method that combined key/value pairs appropriately. Phew.


Leave a Reply

Your email address will not be published. Required fields are marked *

*