I've got some downtime this weekend, so I'm pooring over various examples of
metaprogramming w/ Ruby.
I really like _why's example regarding Dwemthy, but am curious as to how to
achieve my end.
The article in question is here:
_why's method allows us to build 'traits' for the character (by calling the
'trait' class method), and the meta programming behind the scenes builds an
'initialize' instance method for the class.
What if I want to build a second method called 'command'? It should place
the argument in an array that can be referenced later. It will need to also
build an initialize method for my class, but one of them will have to be
Does anyone have any smart ways to combine or chain these two initialize
I ultimately want to do something like this:
class Dragon < Creature
puts "I am flying..."
After an instance is created, it will contain the instance variable
'commands', which is an array holding the symbol 'fly'.
Does anyone have any ideas? In the end, I'd be adding more and more of
these commands to my DSL. This is a DSL, right?