If you feel the necessity of doing that frequently, then your API design is wrong as a Ruby code. Rather than defining methods in function style:
b = f1(a)
c = f2(b)
d = f3(c)
...
define them in OOP style:
class A
def f1; ... end # => b instance
end
class B
def f2; ... end # => c instance
end
class C
def f3; ... end # => d instance
end
Here, A
is the class that a
belongs to, B
is the class that b
belongs to, and so on (A
, B
, ... do not have to be all different. They can be Object
or Kernel
if you want to allow any object). Then, you can simply do chaining as:
a.f1.f2.f3. ...