Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Proc#>>

(::Proc::_Callable callable) -> ::Proc
prc >> g → a_proc

Returns a proc that is the composition of this proc and the given g. The returned proc takes a variable number of arguments, calls this proc with them then calls g with the result.

Example
f = proc {|x| x * x }
g = proc {|x| x + x }
p (f >> g).call(2) #=> 8

g could be other Proc, or Method, or any other object responding to call method:

Example
class Parser
  def self.call(text)
     # ...some complicated parsing logic...
  end
end

pipeline = File.method(:read) >> Parser >> proc { |data| puts "data size: #{data.count}" }
pipeline.call('data.json')

See also Method#>> and Method#<<.

See also #=== #[] #== #arity also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0