1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
class Proc def *(n) proc do |arg| input = arg output = nil n.times do output = self.call(input) input = output end output end end end x = proc { |n| n + 1 } p x*5 p (x*5).call(1)
1 2
#<Proc:0x401bfa54@t.rb:4> 6