w3d4 notes Flashcards

1
Q

What does the following do?

a, b, c = *Array.new(3, 2)

A

Sets a, b, and c to 2, because a 3 element array of 2s is created with #new, and splat separates out the values.

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

T/F: Never override #initialize in Rails.

A

T

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

What happens when you discard an instance of a model?

A

The db is left untouched, unless you use #destroy

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

Why should you not use instance variables in Rails?

A

They do not persist; the values of them are unreliable.

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

What should you use instead of ::count? Why?

A

You should use #length, b/c ::count will fire the query.

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

What should you use in SQL to check for equivalency to NULL?

A

IS NULL

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

Does SQL have short-circuiting?

A

No

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

How should you structure associations to avoid data duplication?

A

Only connect models in a linear fashion.

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