Module: Cuprum::Currying
- Included in:
- Command
- Defined in:
- lib/cuprum/currying.rb,
lib/cuprum/currying/curried_command.rb
Overview
Implements partial application for command objects.
Partial application (more commonly referred to, if imprecisely, as currying) refers to fixing some number of arguments to a function, resulting in a function with a smaller number of arguments.
In Cuprum’s case, a curried (partially applied) command takes an original command and pre-defines some of its arguments. When the curried command is called, the predefined arguments and/or keywords will be combined with the arguments passed to #call.
Defined Under Namespace
Classes: CurriedCommand
Instance Method Summary collapse
-
#curry(*arguments, **keywords, &block) ⇒ Cuprum::Currying::CurriedCommand
Returns a CurriedCommand that wraps this command with pre-set arguments.
Instance Method Details
#curry(*arguments, **keywords, &block) ⇒ Cuprum::Currying::CurriedCommand
Returns a CurriedCommand that wraps this command with pre-set arguments.
When the curried command is called, the predefined arguments and/or keywords will be combined with the arguments passed to #call.
The original command is unchanged.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cuprum/currying.rb', line 68 def curry(*arguments, **keywords, &block) return self if arguments.empty? && keywords.empty? && block.nil? Cuprum::Currying::CurriedCommand.new( arguments: arguments, block: block, command: self, keywords: keywords ) end |