Earlier quoted context omitted.
there are many ways to lookup if something is defined or not instance_variable_defined? defined? are two common ones but if you are using something before defining it you are going to crash so that's definitely one way of distinguishing it. using fetch is another way to provide a default value to something that may have a nil value as a meaningful value.
Thanks for correcting me (sincerely) > but if you are using something before defining it you are going to crash so that's definitely one way of distinguishing it. Would you clarify? Like that was my point, casually using something where `nil` is a possible assigned value, or maybe the variable hasn't been defined, makes possible the (sadly common) category of bugs where the program does not crash, but proceeds as tho…
yeah I wouldn't say i love it and i'm not sure why they did that but i imagine they had a reason for it originally. i would say it should have crashed instead of return nil as a default. they did tend to try to make the programmer happier and maybe they did it to that end but i don't see a large upside to it... not too much we can do about not using instance variables though... at the end of the day you just have to be a little more careful.
tests are a pretty good thing to have though and can catch this kind of error.