Another addition to the various metaprogramming tools around (just looked
at Andy's DbC - very cool!):

http://beta4.com/advice.c

It's a simple extension module that allows an "advice" method to be added
to any class object, that controls (executes code before and after, and
chooses whether to call) any instance methods flagged as advised.  Unlike
most of the other method-wrapping stuff, it does it in a tiny bit of C
code rather than with pre-processor style code generation.

For example:

require 'advice'

class Foo
	def Foo.advice(obj, method, args)
		if(args[0] < 0)
			puts "don't like negative numbers"
		else
			result = yield
			puts "result: " + result
		end
	end

	def subtract(x, y)
		x - y
	end

	def add(x, y)
		x + y
	end
end

foo = Foo.new
foo.subtract(3,2) 	#=> 1
foo.add(-1, 1)		#=> 0

Foo.advise(:subtract)
Foo.advise(:add)

foo.subtract(3,2)	#=> 1
#=> result: 1
foo.add(-1, 1)		#=> nil
#=> don't like negative numbers


I mean it mostly as an example, and as a foundation on which to build libs
like AspectR, but it could come in handy all by itself for some things,
too.

Avi