Skip to content

Instantly share code, notes, and snippets.

@laurenhavertz
Last active December 18, 2015 16:59
Show Gist options
  • Save laurenhavertz/5815717 to your computer and use it in GitHub Desktop.
Save laurenhavertz/5815717 to your computer and use it in GitHub Desktop.
WDI Action Adventure
  • Make sure your program is user friendly. FILLED WITH TEXT.

  • Keep it DRY- Always look for repeated code and try to refactor it to a more simple and precise way

  • to wrap text in the command line '/n'

  • $end normally, end of line OR end of file. in an error message if you open an "if" block or loop and don't close it

  • to add a file from a link curl + " " + hyperlink + > instructors.csv (file name)

  • p and print can both take 2 arguments

 info = load()
	infos = info.split("\n")
	infos.each { |x|
		p(x, x.class)
	}
end````

**read about SCOPE in Ruby**

`<<` add things to arrays


***Won't work***
	def main()
	csvtext = load()
	persons= csvtext.split("\n")
	contacts = []
	persons.each { |person|
		fields = person.split(",")
		fields.each{ |field|
			field = field.strip()
		}
		contacts << fields

not in the scope so throws the information away

`.pop` change the object of the array. removes the most previously added object
`.push` adds on to the array
`.unshift` stores at the top of the array (returns the entire array with new object added)
`.shift` returns back first element popped off
`range: ex. 1..100` all of the numbers starting at and including the last number (use `...` to exclude the last number)
`API` Application programable interface..setting a standard way for people to communicate to one another
`=>` HASHROCKET

* pop/push/shift/unshift: modify the array
* each/map: don't modify

`map`: performs operation on each element in the array and outputs each new object in a new array

if something doesn't modify the "self" `!` and the end of the command will modify the self

* return value and output value are different
* `gsub` finds and substitutes in a string
*Boolean operators usually have `?` at the end (ex. is_a? String) => will return `TRUE` or `False`

`each_with_index`: value of whats in the array and also position in the array
	*ex. names.each_with_index {|v,i| puts v + i.to_s }
	
`.select` : method of sorting; will only take string elements
`.include?"` will return boolean value- use would be @usernames
`.uniq` : will return the array without duplicated elements. Does not modify the array

`symbol`: vaule of symbol is the string name 


*hash- loose data trying to make more clear and more accessible/ used to map one unique identity to another

JSON View

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