stupid question: Object#name

M

Mark Hubbart

Class is a template for creating objects. Object is a subclass of
class.

Not quite:
Class.ancestors => [Class, Module, Object, Kernel]
Object.class
=> Class

Class is a sub class of Object, while Object is an instance of Class!

whoops... I didn't say what I meant there. What I said was obviously
wrong :) I meant it the other way around. I should proof my messages
better. :/ Anyway, that was mainly a statement to introduce the link,
which does a much better job of stating things than I did...
 
R

Robert Klemme

Benny said:
<snip: everything other is discussed widely to my
full satisfaction :) >

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:
=> C1
?> c1 == C1.instance
=> false=> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,488
Latest member
MohammedHa

Latest Threads

Top