From: Phrogz Date: 2007-11-24T23:39:59+09:00 Subject: Re: Access modifier : private On Nov 24, 4:57 am, Dharmarth Shah wrote: > Thanks a lot Stefano! That was really helpful. > > One more help. > > What's the rationale in sharing Class level variables with subclasses? > Is there any way to restrict Class level variables and Class level > methods to restrict to class itself? Instead of using class level variables, use instance variables of the class itself. It's what most people want anyhow: irb(main):001:0> class Foo irb(main):002:1> @jim = :foo irb(main):003:1> class << self irb(main):004:2> attr_accessor :jim irb(main):005:2> end irb(main):006:1> end irb(main):007:0> class Bar < Foo irb(main):008:1> @jim = :bar irb(main):011:1> end irb(main):012:0> Foo.jim => :foo irb(main):013:0> Bar.jim => :bar irb(main):014:0> Foo.jim = 42 => 42 irb(main):015:0> Bar.jim => :bar irb(main):016:0> Bar.jim = 'whee' => "whee" irb(main):017:0> Foo.jim => 42 etc.