In references, what does the = sign do even when syntactic sugar is being used? -= or +=
”=” operator will always reassign and create a NEW pointer in memory (the arrows)
When x = 4 and y = x and x += 2, what is y?
y will remain at 4 because x += 2 expands to x + 2 = 6 which is points to another point in memory.
FIXED NUMs are immutable objects. The numbers are already stored in memory therefore we cannot change them.
Integers and floats are immutable. they just provide new values.
What are MUTABLE objects?
Strings, arrays, hashes whether using the shovel operator. When you use the += or -= operators IT WILL create a new space in memory even tho its mutable.
One point is that = does not mutate (modify) an object; it merely reassigns the variable so that it now refers to a new object.
Does the “=” mutate or reassign and hash?
“hash[key] = value” DOES NOT reassign the hash it’s only mutating the key value pairs..
What does the | | operation do?
Ruby is “lazy” and will not evaluate the right side of the or operator if the left side is already true. It’ll pull the first “truthy” value. it knows that regardless of what’s on the right side, if the left and first value is a truthy, then the whole statement will be true.
What is the Single Responsibility Principle?
It’s the principle that methods should do a single thing at a time and should be short. They should be atomic.
What is a rule of thumb for referencing variables in methods?
Should only reference variables that are passed in as arguments and avoid using any global variables
What is code smell?
Not necessarily a bug but indicate weakness in the code design that could possibly lead to bugs down the line or slow down development.
Examples of smells:
1. Duplicated or similar code that doesn’t apply the DRY rule