Module Hook
In: lib/more/facets/hook.rb

TODO: hooks should be an inheritor

Methods

append_features   hook   hooks  

Public Class methods

[Source]

   # File lib/more/facets/hook.rb, line 7
7:   def self.append_features(base)
8:     base.extend self
9:   end

Public Instance methods

[Source]

    # 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

[Source]

    # File lib/more/facets/hook.rb, line 11
11:   def hooks
12:     @hooks ||= Hash.new{ |h,k| h[k] = [] }
13:   end

[Validate]