class Proc def self.compose(f, g) lambda { |*args| f[g[*args]] } end def *(g) Proc.compose(self, g) end end inc = lambda { |x| x + 1 } square = lambda{ |x| x * x} square_inc = square * inc square_inc(2) #=> 9