module Shelike::Pipe

Constants

VERSION

Public Class Methods

build_proc(proc, apply_proc, *args) click to toggle source
# File lib/shelike/pipe.rb, line 3
def self.build_proc(proc, apply_proc, *args)
  case proc
  when Symbol, Method then -> { proc.to_proc.call(apply_proc.call, *args) }
  when Proc           then -> { proc.call(apply_proc.call, *args) }
  else raise ArgumentError
  end
end

Public Instance Methods

^(proc) click to toggle source
# File lib/shelike/pipe.rb, line 54
def ^(proc)
  call.tap { |r| raise Shelike::Pipe::Error::ResultNilError if r.nil? }
rescue => e
  proc.call(e)
  nil
end
|(arg) click to toggle source
# File lib/shelike/pipe.rb, line 12
def |(arg)
  if arg.is_a? Array
    proc_or_method = arg.shift
    Shelike::Pipe.build_proc proc_or_method, -> { self }, *arg
  else
    Shelike::Pipe.build_proc arg, -> { self }
  end
end