- Published
- Author
- Nived HariSystem Analyst
Instead of manually checking if a key exists in a hash, you can just say:
Now whenever you do:
Ruby will assume
#ruby
Code
counts = Hash.new(0)Now whenever you do:
Code
counts[:apple] += 1Ruby will assume
counts[:apple] starts at 0, so no errors — just clean, readable code.#ruby