Thursday, October 29, 2009

Nil objects in Ruby

If everything is an object, what happens when you do not really have an object? For exactly those occasions, Ruby supplies us with a special object that represents the idea of not having an object, of being utterly object-less, sans object. This special
value is nil.

Everything in Ruby is an object, and so it is: nil.we can get the class of nil:
irb(main):011:0> nil.class
=> NilClass
This turns out to be something very predictable,There is only one instance of NilClass (called nil) and you cannot make any new instances of NilClass.

No comments:

Post a Comment