Chapter 4 Flashcards
What is a helper?
A user-defined function in Rails
Where are files for helpers stored?
app/helpers
T/F: Each helper file corresponds to an ERB layout, and provides its functions to it.
T
What is the command to start the rails console?
$rails console
How are ‘puts’ and ‘gets’ pronounced? Why?
as “put ess” and “get ess”, short for put string and get string.
T/F: The ‘print’ function appends a newline character.
F; only ‘puts’ does this
T/F: Single-quote strings support interpolation and escape characters.
F; only double quoted strings allow for interpolation and escape characters; single-quoted strings print all characters as their literal values.
How can we guarantee we never have to deal with the error produced by the following code:
nil.empty?
always change it to a string:
nil.to_s.empty?
returns true
What are the ONLY two ruby objects which return false when used as a boolean?
‘false’ and ‘nil’
How are ‘if’ and ‘unless’ statements related?
Both can be placed after a statement to determine if the preceding statement is executed by evaluating the proceeding statement
What is the point of the ‘!!’ operator?
Used as a unary operator it converts any object to a boolean value
How does the ruby interpreter know whether to read an if statement as the beginning of an if-else block or a condition at the end of a statement?
When used in the same manner as ‘unless’, if statements do not include an ‘end’ keyword
What is the point of the ‘module’ keyword?
It allows classes to use the modules with the ‘include’ keyword
T/F: Ruby arrays can contain more than one type.
T
How can a range be converted to an array?
(0..9).to_a