The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
A Class is not always a Class

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Matt Williams

Posts: 466
Nickname: aetherical
Registered: Feb, 2008

Matt Williams is a jack-of-all trades living in Columbus, OH.
A Class is not always a Class Posted: Jun 25, 2008 9:36 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Matt Williams.
Original Post: A Class is not always a Class
Feed Title: Ruby Blender
Feed URL: http://feeds2.feedburner.com/RubyBlender
Feed Description: This blog contains short-ish ruby tips, hints, and techniques.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Matt Williams
Latest Posts From Ruby Blender

Advertisement

While playing around in irb last night, I discovered something interesting Class does not always have the same superclass:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

>> Class.superclass
=> Module
>> Class.object_id
=> -605542778
>> class Fud
>>   end
=> nil
>> Fud.class
=> Class
>> Fud.object_id
=> -606747838
>> Fud.superclass
=> Object
>> Class.class
=> Class
>> Class.class.superclass
=> Module
>> Fud.class.superclass
=> Module
>> Fud.class.object_id
=> -605542778
>> Fud.class
=> Class
>> Fud.class
=> Class
>> Fud.class.object_id
=> -605542778
>> Fud.superclass
=> Object
>> Fud.instance_of? Class
=> true
>> Class.instance_of? Class
=> true
>> Class.class.object_id
=> -605542778
>> Class.object_id
=> -605542778

Curious, huh? So, despite Fud being an instance of Class, it's superclass is Object. And Class is an instance of itself.

I believe that this has to do with the mysterious "class" object which every class has. This class object allows one to get at the guts, if you will, of a class in order to do metaprogramming.

Still it's pretty interesting...

Read: A Class is not always a Class

Topic: ¡Java es Socialista! Previous Topic   Next Topic Topic: Flex: Anonymous Classes as Test Stubs

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use