|
|||||
|
|
#1 |
|
|
I found a strange thing. Object.cl*** =>Cl*** Cl***.cl*** =>Cl*** As you see, Object and Cl*** are of same type. Object.methods.length =>73 Cl***.methods.length =>74 Cl***.methods - Object.methods =>["nesting"] I expected that Object has same methods as Cl*** but it's not. Can somebody explain and teach me please? Thanks in advance. kong |
|
|
#2 |
|
|
Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sam Sungshik Kong (ssk@chol.nospam.net) wrote: > Hello! >=20 > I found a strange thing. >=20 > Object.cl*** > =3D>Cl*** > Cl***.cl*** > =3D>Cl*** >=20 > As you see, Object and Cl*** are of same type. > > Object.methods.length > =3D>73 > Cl***.methods.length > =3D>74 > Cl***.methods - Object.methods > =3D>["nesting"] >=20 > I expected that Object has same methods as Cl*** but it's not. > Can somebody explain and teach me please? See Module#nesting in ri irb(main):001:0> Object.ancestors =3D> [Object, Kernel] irb(main):002:0> Cl***.ancestors =3D> [Cl***, Module, Object, Kernel] Cl*** and Module have a nesting, while cl***es not descended from Cl*** or Module do not. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --v9Ux+11Zm5mwPlX6 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFA10ZIMypVHHlsnwQRAhn2AJ9FR+xXFN+XCDX13dS5tY 9bGHZOkQCfRKyB NcG8G28T+nzFShcRge7Zlcc= =M6Dd -----END PGP SIGNATURE----- --v9Ux+11Zm5mwPlX6-- |
|
|
#3 |
|
|
$ irb irb(main):001:0> Object.supercl*** => nil irb(main):002:0> Cl***.supercl*** => Module irb(main):003:0> Cheers, Kent. On Jun 21, 2004, at 4:08 PM, Sam Sungshik Kong wrote: > Hello! > > I found a strange thing. > > Object.cl*** > =>Cl*** > Cl***.cl*** > =>Cl*** > > As you see, Object and Cl*** are of same type. > > Object.methods.length > =>73 > Cl***.methods.length > =>74 > Cl***.methods - Object.methods > =>["nesting"] > > I expected that Object has same methods as Cl*** but it's not. > Can somebody explain and teach me please? > > Thanks in advance. > > kong > > > |
|
|
#4 |
|
|
Thanks for your reply.
But I still don't understand it very well. Object is type of Cl***, right? (Object.cl*** -> Cl***) Cl*** has a method - nesting. Then Object should have it because it's type of Cl***. Maybe something in my logic is wrong. Could you point me to it? kong "Kent Sibilev" <ksibilev@bellsouth.net> wrote in message news:E49B7180-C3C0-11D8-8F8A-000A95C700E8@bellsouth.net... > You should care about supercl***, not cl***: > > $ irb > irb(main):001:0> Object.supercl*** > => nil > irb(main):002:0> Cl***.supercl*** > => Module > irb(main):003:0> > > Cheers, > Kent. > > On Jun 21, 2004, at 4:08 PM, Sam Sungshik Kong wrote: > > > Hello! > > > > I found a strange thing. > > > > Object.cl*** > > =>Cl*** > > Cl***.cl*** > > =>Cl*** > > > > As you see, Object and Cl*** are of same type. > > > > Object.methods.length > > =>73 > > Cl***.methods.length > > =>74 > > Cl***.methods - Object.methods > > =>["nesting"] > > > > I expected that Object has same methods as Cl*** but it's not. > > Can somebody explain and teach me please? > > > > Thanks in advance. > > > > kong > > > > > > > > > |
|
|
#5 |
|
|
--Hf61M2y+wYpnELGG
Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Sam Sungshik Kong (ssk@chol.nospam.net) wrote: > Thanks for your reply. > But I still don't understand it very well. >=20 > Object is type of Cl***, right? > (Object.cl*** -> Cl***) > Cl*** has a method - nesting. > Then Object should have it because it's type of Cl***. >=20 > Maybe something in my logic is wrong. > Could you point me to it? Cl*** inherits from Module, Object does not. A Module has a nesting, while an object does not (unless it is a Cl*** or Module). See Module#nesting in ri. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --Hf61M2y+wYpnELGG Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFA11yvMypVHHlsnwQRAh1aAJ4hGAsaEjRCJXmf6GsEYg aXpdxvHgCgsMVb ytfL28KIc/WXfeauG+iQfdU= =zKdO -----END PGP SIGNATURE----- --Hf61M2y+wYpnELGG-- |
|
|
#6 |
|
|
Sam,
'Object', 'Module', and 'Cl***' are all components of Ruby's meta-object protocol, so the relationships between them are a special case. 'Object.cl***' returns 'Cl***', but internally, the Object type is created in the C code that initializes the object model, before that model is complete. In other words, a few core cl***es must be bootstrapped in the runtime to avoid circular inheritance relationships. That can make them appear to violate the usual semantics, but there is really no way aside from layering a cl***-based object model on top of a simpler one (such as simple prototypes) to avoid having certain primitives with special status and semantics. Lennon |
|
|
#7 |
|
|
What version of Ruby are you running? From irb,
Object.cl***.methods.length return 74. Instances of Object and Cl*** should not necessarily have the same number of methods, but Object.cl*** and Cl***.cl*** should since they both return an instance of Cl***. The exception being somewhere someone added or a removed a method from the instance of Cl*** returned by Object.cl***. On Tue, 22 Jun 2004 05:08:21 +0900, Sam Sungshik Kong <ssk@chol.nospam.net> wrote: > > Hello! > > I found a strange thing. > > Object.cl*** > =>Cl*** > Cl***.cl*** > =>Cl*** > > As you see, Object and Cl*** are of same type. > > Object.methods.length > =>73 > Cl***.methods.length > =>74 > Cl***.methods - Object.methods > =>["nesting"] > > I expected that Object has same methods as Cl*** but it's not. > Can somebody explain and teach me please? > > Thanks in advance. > > kong > > |
|
|
#8 |
|
|
Hi!
I'm using Ruby 1.8. Object.cl***.methods.length #->74 Object.methods.length #->73 Object.cl*** is Cl***. Object is type of Cl***. I'm still confused with cl*** and object and metacl***... Sam "wilkes joiner" <wilkesjoiner@gmail.com> wrote in message news:b832a2c7040621165233d5a0a5@mail.gmail.com... > What version of Ruby are you running? From irb, > Object.cl***.methods.length return 74. > > Instances of Object and Cl*** should not necessarily have the same > number of methods, but Object.cl*** and Cl***.cl*** should since they > both return an instance of Cl***. The exception being somewhere > someone added or a removed a method from the instance of Cl*** > returned by Object.cl***. > > On Tue, 22 Jun 2004 05:08:21 +0900, Sam Sungshik Kong > <ssk@chol.nospam.net> wrote: > > > > Hello! > > > > I found a strange thing. > > > > Object.cl*** > > =>Cl*** > > Cl***.cl*** > > =>Cl*** > > > > As you see, Object and Cl*** are of same type. > > > > Object.methods.length > > =>73 > > Cl***.methods.length > > =>74 > > Cl***.methods - Object.methods > > =>["nesting"] > > > > I expected that Object has same methods as Cl*** but it's not. > > Can somebody explain and teach me please? > > > > Thanks in advance. > > > > kong > > > > > > |
|
|
#9 |
|
|
"Sam Sungshik Kong" <ssk@chol.nospam.net> schrieb im Newsbeitrag news aHBc.6843$_e1.3669@newssvr27.news.prodigy.co m...> Hello! > > I found a strange thing. > > Object.cl*** > =>Cl*** > Cl***.cl*** > =>Cl*** > > As you see, Object and Cl*** are of same type. > > Object.methods.length > =>73 > Cl***.methods.length > =>74 > Cl***.methods - Object.methods > =>["nesting"] > > I expected that Object has same methods as Cl*** 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 cl*** they need not have the same number of methods, because methods can be defined on a per instance basis. Consider: irb(main):015:0> cl*** Foo; def test; "test"; end; end => nil irb(main):016:0> f1 = Foo.new => #<Foo:0x1016f920> irb(main):017:0> f2 = Foo.new => #<Foo:0x1016c788> irb(main):018:0> cl*** << f2; def test2; "test2"; end; end => nil irb(main):019:0> f1.cl*** => Foo irb(main):020:0> f2.cl*** => 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 |
|
|
#10 |
|
|
"Sam Sungshik Kong" <ssk@chol.nospam.net> wrote
> I'm using Ruby 1.8. > > Object.cl***.methods.length #->74 > Object.methods.length #->73 > > Object.cl*** is Cl***. > Object is type of Cl***. > > I'm still confused with cl*** and object and metacl***... Hi Sam -- The key is that what cl*** an object is doesn't say everything about what methods it has, because of the existence of singleton methods. [And the list of methods an object has doesn't say everything about what messages it responds to, because of the existence of method_missing - though this is irrelevant to your question ] JamesBritt's recent message http://www.ruby-talk.org/104273 explains this, though without mentioning singleton methods explicitly. In this case, the additional method ("nesting") is sneaking in as singleton method on Module: irb(main):015:0> Module.singleton_methods => ["constants", "nesting"] constants is also a Module singleton method, but nesting is the only new one: irb(main):016:0> Object.methods.include?("nesting") => false irb(main):017:0> Object.methods.include?("constants") => true ... hence the difference of 1 in the number of methods that Object and Module have. Hope this helps, George. |