Initializing gotcha
I came across an interesting behaviour today. The #initialize method of a class contained some faulty code towards the bottom, but strangely enough the code that came before was …forgotten. Apparently the raised exception made Ruby ignore the instance variables that came before. Observe:
Took me a while to understand what’s going on. It makes sense, though — because of the error, the class won’t be initialized, because the method call doesn’t return anything internally. However, I was expecting the code to be executed up to point where the error occured; i.e. I was surprised to see mc ending up being nil.