Forum: Ruby Drawing a hierarchy w.r.t. class (instance) variables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
47b36de21d7ecbc824c81d24802a6290?d=identicon&s=25 Minkoo Seo (pool007)
on 2006-02-28 07:44
(Received via mailing list)
Hi group.

Recently, I've read

http://www.visibleworkings.com/little-ruby/Chapter3.pdf
http://www.ruby-doc.org/docs/Understanding%20Ruby'...
and PickAxe.

I'm trying to draw a picture of hierarchy for the following:

class Foo
    @@k = 20
end

class Bar < Foo
    @j = 10

    def initialize
        @i = 0
    end
end

b = Bar.new


I understand how to draw hierarchy if it were not for class variables:

            Class
              ^
              |
      +-------+
      |       |
    (Foo) <-(Bar)
      ^       ^ - Bar's class methods
      |       |
     Foo  <- Bar
              ^ - j and Bar's instance methods
              |
              b
                - i

In this picture parenthesis represents meta class. Upward arrows
represents 'class', while leftward arrows represents 'inherits'.

But, I have no idead where the class variable k should belong to. k is
shared by Foo and Bar which menas that if k is modified at Foo, then
the value of k at Bar will be modified also. That being the case, does
k must be drawn under (Foo)? or Class?

Thanks.

- Minkoo Seo
This topic is locked and can not be replied to.