Class: Proc
- Inherits:
-
Object
- Object
- Proc
- Defined in:
- lib/pixee/procs/proc_extension.rb
Overview
Adding methods for easily chaining together procs
Instance Method Summary collapse
-
#*(next_proc) ⇒ Object
Acts as a “map” function for the results of the current proc.
-
#>>(next_proc) ⇒ Object
Pipes the result of the current proc into the next proc.
-
#prepare(*args) ⇒ Object
(also: #prep, #pix)
Prepare the current proc with any additional arguments that should be passed during its creation.
Instance Method Details
#*(next_proc) ⇒ Object
Acts as a “map” function for the results of the current proc
12 13 14 15 16 17 |
# File 'lib/pixee/procs/proc_extension.rb', line 12 def *(next_proc) ->(*args) { result = self.call(*args) result.map {|r| next_proc.call(r)} } end |
#>>(next_proc) ⇒ Object
Pipes the result of the current proc into the next proc
4 5 6 7 8 9 |
# File 'lib/pixee/procs/proc_extension.rb', line 4 def >>(next_proc) ->(*args) { result = self.call(*args) next_proc.call(result) } end |
#prepare(*args) ⇒ Object Also known as: prep, pix
Prepare the current proc with any additional arguments that should be passed during its creation. You do not need to prepare if your proc takes no arguments aside from the output of the prior proc
23 24 25 26 27 28 |
# File 'lib/pixee/procs/proc_extension.rb', line 23 def prepare(*args) ->(*proc_args) { proc_args += args self.call(*proc_args) } end |