Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
When an instance variable is accessed but hasn’t been assigned a value yet, the Ruby interpreter will return nil without complaint. It is therefore entirely unnecessary to initialize instance variables to nil. The only reason you might still perform this superfluous task is to silence warnings when invoking Ruby with the -w flag, which turns on warnings.[6]
[6] Not being forced to initialize instance variables is a Ruby language feature intended to reduce code size. Why would I want a warning about using it? In my opinion, this reduces the usefulness of the -w flag somewhat.
Similarly, it isn’t necessary to initialize local variables to nil either. When a method is entered, the interpreter creates an array to hold all local variables of the method and initializes its entries to a defined value: nil.