###Cheat Sheet
####Arrays
Creating Arrays
my_array = ["Apples", "Oranges", "Pears"]
["Apples", "Oranges", "Pears"]
my_array = Array.new
[]
Array.new(3)
[nil, nil, nil]
Array.new(3, "BEWD")
["BEWD", "BEWD", "BEWD"]
Assessing Elements
arr = ["NYC", "LDN", "LA", "SF", "BOS", "BER"]
arr[0]
arr[100]
arr[-3]
NYC
nil
SF
arr[2, 3] #=> [3, 4, 5]
["LA", "SF", "BOS"]
arr[1..4]
[LDN, LA, SF, BOS]
####Hashes
GA_Markets = { "New York City"=>"NYC", "London"=>"LDN", "Los Angeles"=>"LA", "San Francisco"=>"SF", "Boston"=>"BOS", "Berlin"=>"BER" }
GA_Markets["London"]
"LDN"
super_heros = { batman: "Bruce Wayne", superman: "Clark Kent", spiderman: "Peter Parker"}
super_heros[:superman]
"Clark Kent"
####Loops
Iterator loop
4.times do
puts "This will be printed 4 times"
end
This will be printed 4 times
This will be printed 4 times
This will be printed 4 times
This will be printed 4 times
Each Loop
# A list of GA Courses
courses = [ "FEWD", "BEWD", "CSF" ]
names.each do|n|
puts "GA has a course on #{n}"
end
GA has a course on FEWD
GA has a course on BEWD
GA has a course on CSF
###Tips, Tricks & Motivation
- The Best Way to Learn Ruby & Rails
- What is iteration - article
###Still Feel Lost? ####Catch Up With These Resources
-
Teddit Hashes Answer Video by Steven Nuñez on behalf of General Assembly
- password=> BEWD_GA
-
Arrays Ruby Docs
-
Hashes Ruby Docs
-
Hashes and Arrays Tutorial
-
“Ruby-esque” Loops see page 1 for more ruby loops not covered in class.
Great cheat sheet!
I think there is a typo for this one
arr[2, 3]
should be evaluated as ["LA", "SF"].
I don't think there should be a "BOS".