Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
21 Cards in this Set
- Front
- Back
Print all the words in docs.words
|
docs.words.each { |word| puts word }
|
|
Which format should Classes be in?
|
CamelCased
|
|
Which format should methods, arguments and variables be in?
|
snake_cased
|
|
Which format should constants be in?
|
SNAKED_UPPERCASE
|
|
What is a better way to write the following:
if not @read_only |
unless @read_only
|
|
What is a better way to write the following:
while ! document_is_printed? |
until document.printed?
|
|
One liner to conditionally set @title to new_title only if the document is not read only.
|
@title = new_title unless @read_only
or @title = new_title if @writable |
|
One liner to call document.print_next_page only if document is not printed or has pages available.
|
document.print_next_page while document.pages_available?
or document.print_next_page until document.printed? |
|
How does ruby treat bools?
|
Only false or nil are treated as false. Everything else is true.
|
|
What does a ternary operator look like in ruby?
|
file = all ? 'specs' : 'latest_specs'
if all is true, 'specs' is returned if all is false, 'latest_specs' is returned |
|
How would you initialize a variable only if the variable is nil?
|
@first_name ||= ' '
Set the new value of @first_name to the old value of @first_name, unless that is nil, in which case set it to the empty string |
|
What should you avoid doing when using ||= to initialize things?
|
Avoid initializing booleans
|
|
What is a shortcut for creating an array of strings?
|
poem_words = %w{ twinkle little star how I wonder }
|
|
What is a shortcut for creating hashes?
|
book_info = { first_name: 'Russ', last_name: 'Olsen' }
|
|
How would you make a method that takes an arbitrary set of arguments?
|
def some_method( *args* )
|
|
How do multiple arguments get parsed when using a splat?
|
They are passed in as an array
|
|
What is the shortcut for passing a hash as an argument?
|
load_font( :name => 'times roman', :size => 12)
or load_font :name => 'times roman', :size => 12 |
|
How would you use an each block to access data in a hash?
|
movies.each { |name, value| puts "#{name} => #{value}" }
|
|
How is .map different from .each?
|
.map creates a new array containing everything that the block returns
It is useful for transforming the contents of a collection en masse |
|
What does .inject do?
|
Every time it calls the block, it replaces the current result with the return value of the previous call to the block. It returns the result as its return value when it runs out of elements.
|
|
How would you run a method in place on an object rather than returning a new object? (For many methods, not all)
|
Add a bang to the method (Example: a.reverse! )
|