Hi --

On Wed, 20 Jun 2007, Rick DeNatale wrote:

> On 6/19/07, Robert Dober <robert.dober / gmail.com> wrote:
>
>> I do not want to argue with the wise guys if it is an error - I
>> clearly thought so but that is not important ;)
>> But it really would have saved me an hour of debugging if the doc
>> stated clearly that singletons are not included. I thought this might
>> help others and as it took me 20s to vim the missing line into class.c
>
> As far as I can tell, singleton classes aren't mentioned in the doc.
> The documentation borders on folklore.
>
> Singletons as a means of implementing both individual instance, and
> class behavior have a position like "the man behind the curtain" in
> "The Wizard of OZ."  We're really supposed to disregard them. <G>
>
> Coming from a background in Smalltalk, my preference would be if this
> machinery were more visible and official, but Matz has his reasons for
> not doing so.  For one thing, not documenting it, and hiding it from
> methods like ancestors and class makes it easier to tinker with as the
> language evolves without "officially" breaking backward compatibility.

Does that mean that no one who's ever used Smalltalk can ever think
that it's right for Ruby to deviate from Smalltalk? :-)  I ask in a
humorous spirit -- and also because it gives me an excuse to mention:

http://www.infoq.com/articles/coming-from-ruby

:-)

I think the singleton class has always had a somewhat equivocal
position.  I tend to root for it being treated as a real class, if a
somewhat special-purposed one, since it *is* a real class (and neither
virtual nor meta).  That could change, of course.  Matz has always
described it as just the way that per-object behavior happens to be
implemented in Ruby -- and a case could certainly be made that classes
are an odd choice for that, since, while there are no hard-and-fast
rules about it, the first things most of us probably think of are
instantiation and inheritance and such, none of which can happen with
a singleton class.

Kernel#singleton_class would help a lot... or #singleton_module, if it
goes in that direction :-)


David

-- 
* Books:
   RAILS ROUTING (new! http://safari.awprofessional.com/9780321509246)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)