Expressions and Operators Flashcards
What is an expression?
An expression is a chunk of Ruby code that the Ruby interpreter can evaluate to produce a value.
What does the keyword “self” evaluate to?
the current object
What does the __FILE__ evaluate to?
a string that names the file that the Ruby interpreter is executing
What does __LINE__ evaluate to?
an integer that specifies the line number within __FILE__ of the current line of code.
What are the 4 kinds of variables in Ruby?
- global (begin with $)
- instance variables (begin with @)
- class variables (being with @@)
- local variables (begin with _ or lowercase letter)
What does it mean if :: appears in an expression?
It usually means a reference to a constant but might also indicate a method.
What error is thrown if you use a class variable before it is initialized?
NameError
What does Ruby return with an uninitialized instance variable?
What does an unitialized global variable evaluate to?
What error is thrown if you try to use an identifier that does not have a local variable or a method associated with it?
NameError
The Ruby interpreter enforces the constancy of constants. T/F?
False. It only issues a warning if the value of the constant is changed.
What does :: do in a compound expression?
It separates the name of the constant from the class or module in which it is defined.
Constants can be defined in nested namespaces like this:
Conversions::Area::HECTATRES_PER_ACRE
T/F?
What ahppened if the left hand side is omitted from :: in a constant reference?
The constant is looked up in the global scope.