ruby-uebungen/Assignment_021/solution/readme.md

14 lines
154 B
Markdown
Raw Permalink Normal View History

2023-05-25 17:47:19 +02:00
# Lösung: Closure
2023-05-23 09:19:31 +02:00
2023-05-25 17:49:42 +02:00
```ruby
2023-05-25 17:47:19 +02:00
def create_counter
n = 0 # closure
Proc.new { n += 1 }
2023-05-23 09:19:31 +02:00
end
2023-05-25 17:47:19 +02:00
p = create_counter
puts p.call # -> 1
puts p.call # -> 2
2023-05-23 09:19:31 +02:00
```