Dwemthy’s Array is a dungeon adventure game written in Ruby by _why the lucky stiff. It is a showcase of Ruby metaprogramming — particularly the use of method_missing, class macros, and DSL design. The game is short enough to read in one sitting but deep enough to teach real Ruby techniques.
The Creature Module
module Creature
def self.included(base)
base.instance_eval do
def traits(*arr)
arr.each do |trait|
attr_accessor trait
define_method(trait.to_s + '=') do |val|
instance_variable_set('@' + trait.to_s, val)
end
end
end
end
end
end
class Rabbit
include Creature
traits :life, :strength, :charisma, :weapon
def initialize
@life = 10
@strength = 2
@charisma = 44
@weapon = 4
end
end
The Array
class DwemthysArray < Array
alias _push push
def push(val)
_push val
self
end
def >>(val)
push(val)
end
end
Why It Matters
Dwemthy’s Array demonstrates that Ruby DSLs can look like entirely different languages. The traits macro, the >> operator for adding enemies to a dungeon array, the Creature module mixin — these patterns appear throughout production Ruby code. Rails uses similar approaches for has_many, validates, and other class-level macros.
The complete source and an extended version are archived in the whymirror GitHub organization.