58bc23516c | ||
---|---|---|
.. | ||
readme.md |
readme.md
Lösung: Closure
def create_counter
n = 0 # closure
Proc.new { n += 1 }
end
p = create_counter
puts p.call # -> 1
puts p.call # -> 2
58bc23516c | ||
---|---|---|
.. | ||
readme.md |
def create_counter
n = 0 # closure
Proc.new { n += 1 }
end
p = create_counter
puts p.call # -> 1
puts p.call # -> 2