I’ve finished the first of my 7 languages, and in just under the week. Go me. The final chapter on Ruby focuses on the metaprogramming aspects of the language which are some of the things that Ruby fans seem to love.
We start with adding methods to existing classes. This is something that .net has some ability to do since the introduction of extension methods, but Ruby really adds the methods to the class unlike C# where it just adds different locations to look for it, so it doesn’t look like you’ll need to include references to different assemblies and namespaces and whatnot to find the method.
Next up is method_missing which is a very nice technique indeed. Basically it passes the name of the method being called as a parameter so that it can be dealt with in code. The example given was an api for roman numerals so you could enter Roman.XIV or Roman.VII for example and the numeral would be parsed and a number returned.
The chapter ended with a section on modules. I felt that this was not as clear as what had come before it unfortunately, though by the end of the section and with a bit of fiddling I was starting to get an idea about some of the things that it was showing. Certainly enough to be interested in finding out more about the language.
The self study for this day only had one task which was to extend the module that we’d written to handle CSV files with some metaprogrammed method_missing goodness. This went a lot quicker and smoother that day 2’s exercises, but again it would have been nice to see a completed version to compare against mine.
As an intro to Ruby it was short and sweet. I certainly can’t claim to have learned Ruby yet, but I’m undeniably further on than I was and keen to learn more in depth. I was able to pick up a copy of the pickaxe book from pragprog whilst they were running it on super special offer prices, so this will be happening sooner rather than later. Following IronRuby’s recent release of Visual Studio integration tooling, I’m looking forward to seeing how it can help my .net based apps.
No comments:
Post a Comment