Module: Invokable::Core
- Includes:
- Compose
- Defined in:
- lib/invokable/core.rb
Overview
This module should not be used directly.
The core methods that are mixed into classes at a class and instance level when they include Invokable.
Instance Method Summary collapse
-
#===(obj) ⇒ Object
Call invokable with one argument, allows invocables to be used in case statements and Enumerable#grep.
-
#[](*args) ⇒ Object
For Proc compatibility, forwards it’s arguments to “call”.
-
#arity ⇒ Integer
Return the arity (i.e. the number of arguments) of the “call” method.
-
#curry(arity = nil) ⇒ Proc
Return a curried proc.
-
#memoize ⇒ Proc
Return a memoized proc, that is, a proc that caches it’s return values by it’s arguments.
-
#to_proc ⇒ Proc
Return a Proc that forwards it’s arguments along to call.
Methods included from Compose
Instance Method Details
#===(obj) ⇒ Object
Call invokable with one argument, allows invocables to be used in case statements and Enumerable#grep.
61 62 63 |
# File 'lib/invokable/core.rb', line 61 def ===(obj) call(obj) end |
#[](*args) ⇒ Object
For Proc compatibility, forwards it’s arguments to “call”.
53 54 55 |
# File 'lib/invokable/core.rb', line 53 def [](*args) call(*args) end |
#arity ⇒ Integer
Return the arity (i.e. the number of arguments) of the “call” method.
46 47 48 |
# File 'lib/invokable/core.rb', line 46 def arity method(:call).arity end |
#curry(arity = nil) ⇒ Proc
Return a curried proc. If the optional arity argument is given, it determines the number of arguments. A curried proc receives some arguments. If a sufficient number of arguments are supplied, it passes the supplied arguments to the original proc and returns the result. Otherwise, returns another curried proc that takes the rest of arguments.
27 28 29 |
# File 'lib/invokable/core.rb', line 27 def curry(arity = nil) to_proc.curry(arity) end |
#memoize ⇒ Proc
Return a memoized proc, that is, a proc that caches it’s return values by it’s arguments.
34 35 36 37 38 39 |
# File 'lib/invokable/core.rb', line 34 def memoize lambda do |*args| @memo ||= {} @memo[args.hash] ||= call(*args) end end |
#to_proc ⇒ Proc
Return a Proc that forwards it’s arguments along to call.
14 15 16 17 18 |
# File 'lib/invokable/core.rb', line 14 def to_proc lambda do |*args| call(*args) end end |