[ create a new paste ] login | about

Link: http://codepad.org/mpfJMjwW    [ raw code | output | fork ]

Ruby, pasted on Feb 15:
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)


Output:
1
2
#<Proc:0x401bfa54@t.rb:4>
6


Create a new paste based on this one


Comments: