Class: Functor
- Inherits:
-
Object
show all
- Defined in:
- lib/functor.rb
Defined Under Namespace
Modules: Method
Classes: NoMatch
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize {|_self| ... } ⇒ Functor
Returns a new instance of Functor.
82
83
84
85
|
# File 'lib/functor.rb', line 82
def initialize( &block )
class << self; include Functor::Method; end
yield( self ) if block_given?
end
|
Class Method Details
.cache_config(options = {}) ⇒ Object
5
6
7
|
# File 'lib/functor.rb', line 5
def self.cache_config(options={})
(@cache_config ||= { :size => 4_096, :base => 8 }).merge!(options)
end
|
.match?(args, pattern) ⇒ Boolean
95
96
97
98
99
100
|
# File 'lib/functor.rb', line 95
def self.match?( args, pattern )
args.all? do |arg|
pat = pattern[args.index(arg)]
pat === arg || ( pat.respond_to?(:call) && pat.call(arg))
end if args.length == pattern.length
end
|
Instance Method Details
#[](*args, &block) ⇒ Object
91
|
# File 'lib/functor.rb', line 91
def []( *args, &block ); call( *args, &block ); end
|
#given(*pattern, &action) ⇒ Object
87
88
89
|
# File 'lib/functor.rb', line 87
def given( *pattern, &action )
(class << self; self; end)._functor( "call", false, *pattern, &action)
end
|
#to_proc ⇒ Object
93
|
# File 'lib/functor.rb', line 93
def to_proc ; lambda { |*args| call( *args ) } ; end
|