Peter Miller

Musings on Technology and Programming
in

Ruby Chips - Part 3 (why meta this)



If you are in the business of software development, one of your biggest enemies has to be complacency. I am a problem solver; if I ever felt like I had already solved every problem I was likely to encounter while programming, I'd quit. Luckily the web and blogs are around to provide me a steady stream of challenges.

In this installment of Ruby Chips, I thought I'd share 2 posts I've come across in the past few months that have presented me with some challenges. Both of these postings are from why, who is one of my favorite creative people in the Ruby world, and about metaprogramming.

First off, is this post and this chapter by why about metaprogramming. If you haven't had much experience with metaprogramming, then this a good post to read...slowly.

Metaprogramming basically involves writing code that then writes other code. Why uses the example of a simple dungeon crawl game and creating specific sub-classes of the base Creature with very compact syntax such as:
class Dragon < Creature
life 1340 # tough scales
strength 451 # bristling veins
charisma 1020 # toothy smile
weapon 939 # fire breath
end

If this sounds strange, then at least you're interested, and it is definitely worth the read and the exposure to why's unique brand of writing and to metaprogramming. Metaprogramming is a prevalent technique in Ruby and in a future post, I'll take a look at metaprogramming in Ruby on Rails and what value it provides.

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)