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 <<-CODE
def #{name}( *args, &block )
begin
#{klass}.functors[ :#{name} ].apply( self, *args, &block )
rescue ArgumentError => e
begin
super
rescue NoMethodError => f
raise e
end
end
end
CODE
end
functors[ name ].given( *args, &block )
end
end
|