Expressions and Operators Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is an expression?

A

An expression is a chunk of Ruby code that the Ruby interpreter can evaluate to produce a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the keyword “self” evaluate to?

A

the current object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the __FILE__ evaluate to?

A

a string that names the file that the Ruby interpreter is executing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does __LINE__ evaluate to?

A

an integer that specifies the line number within __FILE__ of the current line of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 4 kinds of variables in Ruby?

A
  • global (begin with $)
  • instance variables (begin with @)
  • class variables (being with @@)
  • local variables (begin with _ or lowercase letter)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does it mean if :: appears in an expression?

A

It usually means a reference to a constant but might also indicate a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What error is thrown if you use a class variable before it is initialized?

A

NameError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does Ruby return with an uninitialized instance variable?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does an unitialized global variable evaluate to?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What error is thrown if you try to use an identifier that does not have a local variable or a method associated with it?

A

NameError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The Ruby interpreter enforces the constancy of constants. T/F?

A

False. It only issues a warning if the value of the constant is changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does :: do in a compound expression?

A

It separates the name of the constant from the class or module in which it is defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Constants can be defined in nested namespaces like this:
Conversions::Area::HECTATRES_PER_ACRE

T/F?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What ahppened if the left hand side is omitted from :: in a constant reference?

A

The constant is looked up in the global scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly