From: Robert Klemme Date: 2011-03-10T00:24:55+09:00 Subject: Re: Comparison between C++ and Ruby Variables On Wed, Mar 9, 2011 at 3:56 PM, Mayank Kohaley wrote: >> >> You write "The Class variable in Ruby is similar to static member variable >> of C++."  This is not true. > > > Can you please explain how exactly it is different from static member > variables of C++. I am sorry, there is a ton of material on class variables and their oddities online (even in the archives of this forum). Please look it up. Basically you cannot do that with static member variables in C++: 16:23:10 Temp$ ruby19 cv.rb B1 2 S1 2 B2 1 S2 1 16:23:13 Temp$ cat -n cv.rb 1 class B1 2 @@foo = 1 3 def self.show; p @@foo; end 4 end 5 class S1 < B1 6 @@foo = 2 7 def self.show; p @@foo; end 8 end 9 class B2 10 end 11 class S2 < B2 12 @@foo = 2 13 def self.show; p @@foo; end 14 end 15 class B2 16 @@foo = 1 17 def self.show; p @@foo; end 18 end 19 [B1,S1,B2,S2].each do |cl| 20 puts cl 21 cl.show 22 end 16:23:16 Temp$ Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/