Skip to content

Instantly share code, notes, and snippets.

@yangsu
Created January 28, 2013 03:42
Show Gist options
  • Select an option

  • Save yangsu/4652840 to your computer and use it in GitHub Desktop.

Select an option

Save yangsu/4652840 to your computer and use it in GitHub Desktop.
Ruby Hashes
# Literal Form
numbers = { 1 => 'one', 2 => 'two' }
# => {1=>"one", 2=>"two"}
# Accessing element using key
numbers[1] # => "one"
# Can use symbols as keys
stuff = { :array => [1, 2, 3], :string => 'Hello' }
# => {:array=>[1, 2, 3], :string=>"Hello"}
# Accessing element using key
stuff[:string] # => "Hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment