Class: Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/pixee/procs/proc_extension.rb

Overview

Adding methods for easily chaining together procs

Instance Method Summary collapse

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