12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/functor.rb', line 12
def self.included( k )
def k.functors
@__functors ||= superclass.respond_to?( :functors ) ?
Functor::Method.copy_functors( superclass.functors ) : {}
end
def k.functor( name, *args, &block )
name = name.to_sym
( f = ( functors[ name ] or
( functors[ name ] = Functor.new ) ) ).given( *args, &block )
define_method( name ) { | *args | instance_exec( *args, &f.match( *args ) ) }
end
def k.functor_with_self( name, *args, &block )
name = name.to_sym
( f = ( functors[ name ] or
( functors[ name ] = Functor.new ) ) ).given( *args, &block )
define_method( name ) { | *args | instance_exec( *args, &f.match( self, *args ) ) }
end
end
|