Module 02 Β· Collections & Blocks β Lesson 2 of 6 Β· ~11 min
Hashes
A hash is Ruby's dictionary β with a symbol-key shortcut
Ruby's hash does the same job as Swift's [String: Any] or a JS object. With symbol keys β the common case β Ruby has a shorthand that drops the => entirely:
walker = { name: "Luna", city: "Austin", price_cents: 2500 }Read name: "Luna" as "the key :name maps to \"Luna\"" β it's exactly :name => "Luna" under the hood, just shorter to write. This is the form you'll see everywhere in Ruby and Rails.