# Bug report involving class variables

**URL:** <https://www.ruby-forum.com/t/bug-report-involving-class-variables/167921>\
**Category:** Ruby\
**Created:** [May 14, 2009, 1:25am UTC](https://www.ruby-forum.com/t/bug-report-involving-class-variables/167921 "2009-05-14T01:25:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Ballou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f14d63/32.png) [@Ken\_Ballou](https://www.ruby-forum.com/u/Ken_Ballou)\
**Post date:** [May 14, 2009, 1:25am UTC](https://www.ruby-forum.com/t/bug-report-involving-class-variables/167921/1 "2009-05-14T01:25:47Z")

</div>

(Slight rant: I tried to submit this bug report through the tracker  
system at [redmine.ruby-lang.org](http://redmine.ruby-lang.org). After trying twice to get a username  
and password [since the first attempt would not recognize the username  
and password even after I clicked the “confirm” link], I was finally  
able to log in. When I tried to submit a new issue report, the form  
complained that the “mailing-list” field could not be blank, even though  
there were no choices in the drop-down box and I could not type in the  
text area. I gave up.)

OK, on to the bug report. Since I didn’t really understand the example  
of class variables on pages 337-8 of “Programming Ruby 1.9”, I decided  
to try the code. I found that the output was different for Ruby 1.9.0  
and Ruby 1.9.1p129, and neither agreed with the book. This seems like  
it may be a defect in Ruby 1.9.

Version information:

1.9.0: ruby -v reports “ruby 1.9.0 (2006-06-08) [x86\_64-linux]”  
1.9.1: ruby -v reports “ruby 1.9.1p129 (2009-05-12 revision 23412)  
[i686-linux]”

Here is the code I used for this test:

##### begin classvars.rb

class Holder  
@@var = 99  
def Holder.var=(val)  
@@var = val  
end  
def Holder.read\_var  
@@var  
end  
def var  
@@var  
end  
end

@@var = “top level variable”

a = Holder.new  
puts “a.var: #{a.var}”  
Holder.var = 123  
puts “a.var: #{a.var}”

def a.get\_var  
@@var  
end

puts “a.get\_var: #{a.get\_var}”  
puts “@@var: #{@@var}”  
puts “Holder.read\_var: #{Holder.read\_var}”

##### end classvars.rb

Here is the output:

Ruby 1.9.0:

a.var: 99  
a.var: 123  
a.get\_var: top level variable  
@@var: top level variable  
Holder.read\_var: 123

Ruby 1.9.1p129:

a.var: top level variable  
a.var: 123  
a.get\_var: 123  
@@var: 123  
Holder.read\_var: 123

(I’m not entirely sure I understand why the first call to a.var should  
return the string “top level variable” but the second should return the  
Fixnum 123 as the book claims, but that’s not part of the bug report.)

Perhaps someone who has more luck than I do with the issue tracker  
system can enter this report?

Thank you, and I vaguely apologize for the rant. I’m just feeling  
beaten up by the issue tracker system.

```
      - Ken

```

---

<div class="post-metadata">

**Author:** ![Ken\_Ballou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f14d63/32.png) [@Ken\_Ballou](https://www.ruby-forum.com/u/Ken_Ballou)\
**Post date:** [May 14, 2009, 7:36am UTC](https://www.ruby-forum.com/t/bug-report-involving-class-variables/167921/2 "2009-05-14T07:36:51Z")

</div>

Can we get the redmine issues fixed?

Begin forwarded message:
