2. To be or not to be, why do we put "||="?


It was quite obvious that I had to put ||=, but I don't really understand how it works in the code. Can somebody explain?


It's simply an assignation operator, like =, but it assigns the value only if the variable contains nil.


Say, if you want to assign a variable but already haven't done it, then you use ||= .
just remember the real value is only decided by =
fav_value ||= "what"
puts fav_value #prints what

in the same console if you use

fav_value ||= "nice"
puts fav_value #also prints what cus you first assigned what

fav_value = "okay"
puts fav_value #prints okay cus theres =

so we used ||= cus to give an intial "nil" value that is [ ] so that you dont have to use if statement and make it longer.