class Proc

Public Instance Methods

&(other=nil, &block)
Alias for: join
chain(other=nil, &block) click to toggle source

Chains two procs together, returning a new proc. The output from each proc is passed into the input of the next one.

Example:

chain = proc { 1 } | proc { |input| input + 1 }
chain.call #=> 2
# File lib/epitools/core_ext/misc.rb, line 90
def chain(other=nil, &block)
  other ||= block
  proc { |*args| other.call( self.call(*args) ) }
end
Also aliased as: |
join(other=nil, &block) click to toggle source

Join two procs together, returning a new proc. Each proc is executed one after the other, with the same input arguments. The return value is an array of the return values from all the procs.

You can use either the .join method, or the overloaded & operator.

Examples:

joined = proc1 & proc2
joined = proc1.join proc2
newproc = proc { 1 } & proc { 2 }
newproc.call #=> [1, 2]
# File lib/epitools/core_ext/misc.rb, line 76
def join(other=nil, &block)
  other ||= block
  proc { |*args| [self.call(*args), other.call(*args)] }
end
Also aliased as: &
|(other=nil, &block)
Alias for: chain