w1d4 Flashcards
How do you start a fresh project with bundle? What does this do?
bundle init
it creates an empty Gemfile with instructions on how to add gems
What’s the command to create an empty Gemfile with instructions on how to add gems?
bundle init
How do we install the gems for our project?
bundle install
What does bundle install do?
installs the gems for our project that we’ve specified in our Gemfile
Can we pass a has to a method without curly braces?
Yes, only if it’s the final argument passed in.
How can we set up an attr_reader that can only be accessed internally?
private
attr_reader :whatever
What’s a recursive solution for creating a range(start,finish) exclusive method?
ex: range(1,5) => [1,2,3,4]
base case: if start == finish, return [ ]
A: chop off the leftmost number and add to an empty array
B: call range like so: range(start+1,finish)
return A + B
What’s a recursive solution for generating the first n fib numbers?
base cases:
return [ ] if n == 0
return [0] if n == 1
return [0,1] if n == 2
general case:
fibs(n-1).push fibs(n-1)[-2] + fibs(n-1)[-1]
optimize: make one call to fibs
What are the two main reasons to use git?
We can keep track of changes and know who changed what.
Easy to work on a team. Multiple people can work on a project at once.
How do you see the state of your staging area with git?
git status
What does git status do?
Displays the state of your staging area.
How do you see the differences you’ve made in your staging area?
git diff –staged
How do you make a snapshot of your current staging area with git?
git commit -m “this is the commit message”
How do you see all the branches your team is working on?
git branch
What does git branch do?
Shows all the branches your team is working on
How do you add all the files in a directory to git?
git add -A
What does this do:
git add -A
Adds all the files in the current directory into git
How do you see a history of commits/merges/etc made in git?
git log
What does git log do?
Shows a history of commits/merges/etc made in git
How do you switch to a particular branch in git?
git co [branchname]