Module: Functor::Method

Defined in:
lib/functor.rb

Class Method Summary collapse

Class Method Details

.included(k) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/functor.rb', line 6

def self.included( k )
  def k.functors ; @__functors ||= {} ; end
  def k.functor( name, *args, &block )
    unless functors[ name ]
      functors[ name ] = Functor.new
      klass = self.name ; module_eval "        def \#{name}( *args, &block ) \n          begin\n            \#{klass}.functors[ :\#{name} ].apply( self, *args, &block ) \n          rescue ArgumentError => e\n            begin\n              super\n            rescue NoMethodError => f\n              raise e\n            end\n          end\n        end\n      CODE\n    end\n    functors[ name ].given( *args, &block )\n  end\nend\n"