start 2
[sinatra.git] / lib / sinatra / core_ext / metaid.rb
blob415ca17ae16a7448630609c4d3f6ed42f866b4d8
1 # Compliments to why for this:
2 # http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
4 class Object
5    # The hidden singleton lurks behind everyone
6    def metaclass; class << self; self; end; end
7    def meta_eval &blk; metaclass.instance_eval &blk; end
9    # Adds methods to a metaclass
10    def meta_def name, &blk
11      meta_eval { define_method name, &blk }
12    end
14    # Defines an instance method within a class
15    def class_def name, &blk
16      class_eval { define_method name, &blk }
17    end
18 end