A set of methods to help create meta-programming gizmos.
Defines an instance method within a class
# File lib/meta.rb, line 29 def class_def name, &blk class_eval { define_method name, &blk } end
Adds methods to a metaclass
# File lib/meta.rb, line 24 def meta_def name, &blk meta_eval { define_method name, &blk } end
Evaluates the block in the context of the metaclass
# File lib/meta.rb, line 11 def meta_eval(&blk) metaclass.instance_eval(&blk) end
Acts like an include except it adds the module's methods to the metaclass so they act like class methods.
# File lib/meta.rb, line 17 def meta_include mod meta_eval do include mod end end
The metaclass is the singleton behind every object.
# File lib/meta.rb, line 4 def metaclass class << self self end end