From: Robert Klemme Date: 2004-08-10T15:46:16+09:00 Subject: Re: stupid question: Object#name "Benny" schrieb im Newsbeitrag news:2npjbbF3ak29U1@uni-berlin.de... > full satisfaction :) > > Robert Klemme wrote: > > >>> o1 = Class.new > > => # > >>> o2 = o1.new > > => #<#:0x10188d70> > >>> o2.class > > => # > >>> p1 = Object.new > > => # > >>> p2 = p1.new > > NoMethodError: undefined method `new' for # > > from (irb):6 > > > > You can create instances of a class but not of an object. > class C1 > include Singleton > end > p2 = C1.new #=> NoMethodError: private method `new' called... > > You cannot create instances of some classes as well. Now is a singleton > class more like a class or more like an object? A singleton class is a special class. You can create at least one instance from it although not directly. But it is nevertheless a class. It doesn't loose the capability of creating instances just because you can't access it directly: >> require 'singleton' => true >> class C1 >> include Singleton >> end => C1 >> C1.instance => # >> C1.instance => # >> C1.instance.id => 134972744 >> c1 = C1.instance_eval { new } => # >> c1.id => 134668156 >> c1.class => C1 >> c2 = C1.instance_eval { new } => # >> c2.id => 134616292 >> c2.class => C1 ?> c1 == C1.instance => false >> c2 == C1.instance => false >> c1 == c2 => false > I am not yet convinced that the differences are that big. > ok, its called in another manner but largely behaving the same way. why > should Object not just be another special class as C1 is? The instance "Object" is a class. But instances of Object are not classes and hence cannot create instances (see above). While the object "Class" is a class as well as instances that are created from it; so they can create new instances. Regards robert