Module | Hook |
In: |
lib/more/facets/hook.rb
|
TODO: hooks should be an inheritor
# File lib/more/facets/hook.rb, line 15 15: def hook(name) 16: name = name.to_sym 17: 18: (class << self; self; end).class_eval %{ 19: def #{name}(meth=nil, &blk) 20: hooks[:#{name}] << (meth || blk) 21: end 22: } 23: 24: module_eval %{ 25: def #{name}(*args) 26: self.class.hooks[:#{name}].each do |blk| 27: if Proc === blk 28: instance_exec(:#{name}, *args, &blk) 29: else 30: __send__(blk, :#{name}, *args) 31: end 32: end 33: end 34: } 35: end