w2d1 revisions Flashcards
What Git commands should be entered into your PC every morning?
git config –local user.name= ‘pair1 + pair2’
git config –local user.email = ‘pair1 + pair2@appacademy.io’
What tense should be used for commits?
Present tense
What does the Comparable#between? function do?
Checks if a number lies within a given range, inclusive:
2.between?(0..2)
=>true
What does Array#flatten do?
Reduces a multidimensional array to a 1 dimensional array.
Can an instance variable end in a ‘?’
No; but you can define a function to do so, since you can’t simply use attr_reader:
@sitting = false
def sitting?
@sitting
end
What is going on the following function:
def neighbors adjacent_coords = DELTAS.map do |(dx, dy)| [pos[0] + dx, pos[1] + dy] end.select do |row, col| [row, col].all? do |coord| coord.between?(0, @board.grid_size - 1) end end
adjacent_coords.map { |pos| @board[pos] } end
First, it gets an array of all 8 adjacent spaces where the coordinates are valid. Then, it retrieves the tile objects themselves given these coordinates.
What is an easy way to flip a Boolean?
mybool = !mybool
Say we have a 2 element array names ‘arry’; what is the easiest way to retrieve the values from that array and store them in variables?
first, second = arry
What does the following code do:
File.write(filename, YAML.dump(self))
Within a class, writes a YAML representation of that class to a file.
What is an easy way to retrieve a YAML object from a file?
YAML.load_file(filename)