forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
Ruby Hashes
Quincy Larson edited this page Aug 20, 2016
·
1 revision
- Ruby hashes are comparable to Javascript objects or dictionaries in languages like Python.
- Hashes contain items that are stored by
key: value
pairs. - Ruby hashes can be created using the following methods:
my_hash = {}
my_hash = Hash.new
- There are many methods built into Ruby to find information from and update hashes.
my_hash = {'name' => 'Batman', 'age' => 25}
# is equivalent to:
my_hash = Hash.new
my_hash['name'] = 'Batman'
my_hash['age'] = 25
# Both of these examples return:
{"name"=>"Batman", "age"=>25}
# here is an alternative way to create the array:
{name: 'Batman', age: 25}
# this example return:
{:name=>"Batman", :age=>25}
# learn more about [symbols here](http://www.randomhacks.net/2007/01/20/13-ways-of-looking-at-a-ruby-symbol/)
Previous | Home |
---|---|
Ruby Arrays | Table of Contents |
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links