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
proc.c
View on GitHub ↗
static VALUE
proc_compose_to_right(VALUE self, VALUE g)
{
return rb_proc_compose_to_right(self, to_callable(g));
}
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')