Skip to content

Instantly share code, notes, and snippets.

@tedi
Created May 15, 2014 14:46
Show Gist options
  • Save tedi/11294235193203906740 to your computer and use it in GitHub Desktop.
Save tedi/11294235193203906740 to your computer and use it in GitHub Desktop.

###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

###Still Feel Lost? ####Catch Up With These Resources

@tedi
Copy link
Author

tedi commented Aug 12, 2014

No difference in result/output. The difference is that the example in the slides is all in one line, vs three lines in this document. One liners are generally used when you have little code that goes in the block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment