ruby-uebungen/Assignment_021/solution/readme.md

14 lines
154 B
Markdown

# Lösung: Closure
```ruby
def create_counter
n = 0 # closure
Proc.new { n += 1 }
end
p = create_counter
puts p.call # -> 1
puts p.call # -> 2
```