TODO: hooks should be an inheritor
Methods
append_features
hook
hooks
Public Class methods
[ + ]
# File lib/more/facets/hook.rb, line 6 def self.append_features(base) base.extend self end
Public Instance methods
[ + ]
# File lib/more/facets/hook.rb, line 14 def hook(name) name = name.to_sym (class << self; self; end).class_eval %{ def #{name}(meth=nil, &blk) hooks[:#{name}] << (meth || blk) end } module_eval %{ def #{name}(*args) self.class.hooks[:#{name}].each do |blk| if Proc === blk blk.call(:#{name}, *args) else __send__(blk, :#{name}, *args) end end end } end
[ + ]
# File lib/more/facets/hook.rb, line 10 def hooks @hooks ||= Hash.new{ |h,k| h[k] = [] } end