Hi --

On Mon, 2 Oct 2006, Timothy Goddard wrote:

> The base level in Ruby runs in the context of an instance of Object.
> When you add base level methods you're actually adding those methods to
> the eigenclass of the main object. The main object in essence is an
> instance of its eigenclass and the eigenclass is a subclass of the
> Object class. You can do this with any Ruby object (except Fixnums,
> which is an annoying inconsistency):

The singleton class/object relationship isn't quite an instance one;
it's a little more "phantom"-like.  It doesn't add a real level to the
"family tree"; an object is still an instance of the thing it was an
instance of before:

class C; end
class D < C; end

d = D.new
sing = class << d; self; end

p D.new.instance_of?(C)      # false
p D.new.instance_of?(D)      # true
p D.new.instance_of?(sing)   # false

So thinking of the singleton class as a subclass of the object's class
might be a little misleading, since the object still relates to its
"birth class" at only one level of remove.


David

-- 
                   David A. Black | dblack / wobblini.net
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org