Ruby is just a delight to work with. I really need to write a book about how easy it is to create new dialectic constructs that improve the way you can write your code using the language. Once upon a time I was chided for the heavy use of macros in my C and C++ code; in Ruby, you can build the language structures dynamically and it just feels so good!
Today I put together a little magic on the Ruby Hash that lets me write really nice DSL extensions.
MethodicHash, I extended the lookup of a value using a key, and added a
method_missing to do a lookup with the name of the missing method as a key:
It might not look like much, but when you’ve embedded a DSL into your code with a require and you’ve backed it with a
MethodicHash, you can say things like
instead of accessing it with a string
or a symbol
making the code ever so much more readable. Hiding coding details like this so simply and easily is one of Ruby’s greatest benefits to the programmer.
MethodicHash is a jumping-off point to more complex dynamics that I’ll be hiding under the surface.
More will definitely be coming.