tl;dr: Ruby Arrays,
Objectives:MVC & Testing , Arrays & Functions ,Networking & HTTP
- array: an Object with ordered storage container
*truthy: "Strings", true, " ", everything else *falsey: nil, false
true || true #=> true true || false #=> false false|| false #=> false
In ruby, it is good practice to default something to nil then assign something value to it later on.
bash$ gem install pry
=> This goes to rubygems.org online to download the "pry" gem
Book: Ruby under a microscope
<strong>Naming convention:</strong>
Use snake_case for methods and variables.
Use CamelCase for classes and modules. (Keep acronyms like HTTP, RFC, XML uppercase.)
Use SCREAMING_SNAKE_CASE for other constants.
The names of predicate methods (methods that return a boolean value) should end in a question mark. (i.e. Array#empty?).
The names of potentially "dangerous" methods (i.e. methods that modify self or the arguments, exit!, etc.) should end with an exclamation mark. Bang methods should only exist if a non-bang method exists. (More on this).
<h4>Homework Review:</h4>
```Ruby
#!/usr/bin/env ruby
# 1. create a literal array of all the names in class
# 2. Accept '-g' or 'n'
# 3. Accept a number for either
# 4. when you get '-g x', split the array into 'x' groups and print them
# 5. when you get '-n x', print out 'x' names
# Bonus 1- Store/ retrieve the array in a json file
# Bonus 2- Keep track of selected names
names = %w[Josh Kevin Travis Dave Kristine Donielle Lauren
Megan Xiao Sharif Theo Ricky Justin Ian Ryan Brian
Alex Elen Lior Tod Karl]
puts "Class size is #{names.length}"
method = ARGV[0]
num = ARGV[1].to_i
if '-g' == method
puts
puts "Dividing class into #{names.length/num} groups of #{num}'s:"
puts
p names.shuffle.each_slice(num).to_a
#p xx is equivalent to puts xx.inspect (prints the value of
#inspect instead of to_s, suitable for debugging)
elsif '-n' == method
puts "selecting #{num} random number of peeps:"
p names.sample(num)
else
puts "Error. Check your input."
end
*Xmodmap - to change your keyboard to Dvorak vs. Querty
*While in Terminal, to get to beginning of line: Ctrl + a
; to get to end of line: Ctrl + e
*for Mac- if you're running into issues opening a non-mac program, press Appl Ctrl then mouse click on the icon to open that way.