On Aug 28, 2006, at 5:22 PM, Stephan Wehner wrote:
> I find the nil object is different from others throughout the ruby
> language since it is kind of global: it can be accessed anywhere in  
> the
> code, and there is only one instance. So I feel it is not wise to  
> allow
> this.

I think the uniformity of the Ruby object model is it's strength.  No
need for lots of special rules about things that are objects and things
that are not really objects and things that are objects but behave a
little differently.

You can have instance variables associated with nil, true, false,
instances of Fixnum, classes, modules, and so on.  The language doesn't
care.

I'm not sure how the scoping of the literal 'nil' is related to the  
issue
of instance variables.  The literal '3' would be considered global in  
that
case also, for example. All the top level class objects are also  
'global'.

Here is something interesting.  I figured that you couldn't reference  
the
singleton class of nil, but it turns out that the singleton class of nil
is NilClass, which makes a lot of sense since there can be one and only
one instance of NilClass, that being the object most commonly known  
as nil!

a = class <<nil; self; end
p a.class	# NilClass

Same thing for true and false, which are also singleton instances (in  
the
design pattern sense) of their respective classes (TrueClass,  
FalseClass).


Gary Wright