Syntax
tags = ["ruby", "web"]
profile = { name: "Ada", active: true }Examples
Reading collection values
A small, runnable example of this syntax.
tags = ["ruby", "web"]
profile = { name: "Ada", active: true }
puts tags.first
puts profile[:name]Best practices
- Use symbols for stable, internal hash keys; use strings when a key naturally comes from external text or JSON.
- Keep examples small while learning, then combine the idea with a real project.
At a glance
- Purpose
- Expressive scripting and applications
- File extension
- .rb
- Runs in
- Ruby interpreter
- Usually used with
- Ruby standard library and gems