From: Sam Sungshik Kong Date: 2004-06-23T01:28:10+09:00 Subject: Re: A question about Class and Object Hi! Thank you for the explanation. Now I understand the concept...maybe...:) I think that Class is a very unique one. All other classes are an instance of Class (Object is an instance of Class). What about Class? It's an instance of itself, right? Class is a concept as well as a thing. To test this strange thing, I tried to subclass Class but it failed. class MyClass < Class end =>TypeError: can't make subclass of Class Now, I created an instance of Class. aClass = Class.new Is aClass a class like Object or just an object like obj (obj = Object.new)? It seems like a class. aaClass = aClass.new #->Works! So Class is actually a class maker. It's instances are classes. That means that to make a class, I don't have to define a class. If I just create an instance of Class, it's a class. When I think of Class and Object, the "chicken and egg" problem comes to my mind. Object is an instance of Class and Class inherits from Object. Which one is first? (Which one should exist first?) I am sorry that what I said is not very structured. Sam "Robert Klemme" wrote in message news:2jq7gfF14nmiuU1@uni-berlin.de... > > "Sam Sungshik Kong" schrieb im Newsbeitrag > news:paHBc.6843$_e1.3669@newssvr27.news.prodigy.com... > > Hello! > > > > I found a strange thing. > > > > Object.class > > =>Class > > Class.class > > =>Class > > > > As you see, Object and Class are of same type. > > > > Object.methods.length > > =>73 > > Class.methods.length > > =>74 > > Class.methods - Object.methods > > =>["nesting"] > > > > I expected that Object has same methods as Class but it's not. > > Can somebody explain and teach me please? > > There is also a general answer in Ruby: even if two instances belong to > the same class they need not have the same number of methods, because > methods can be defined on a per instance basis. Consider: > > irb(main):015:0> class Foo; def test; "test"; end; end > => nil > irb(main):016:0> f1 = Foo.new > => # > irb(main):017:0> f2 = Foo.new > => # > irb(main):018:0> class << f2; def test2; "test2"; end; end > => nil > irb(main):019:0> f1.class > => Foo > irb(main):020:0> f2.class > => Foo > irb(main):021:0> f1.methods.grep(/test/) > => ["test"] > irb(main):022:0> f2.methods.grep(/test/) > => ["test2", "test"] > irb(main):023:0> f2.methods - f1.methods > => ["test2"] > > Regards > > robert >