Forum: Ruby Bug report involving class variables

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2322309897697898316526ca4937ac04?d=identicon&s=25 Ken Ballou (Guest)
on 2009-05-14 01:25
(Received via mailing list)
(Slight rant:  I tried to submit this bug report through the tracker
system at  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)

Here is the code I used for this test:

##### begin classvars.rb
class Holder
    @@var = 99
    def Holder.var=(val)
        @@var = val
    def Holder.read_var
    def var

@@var = "top level variable"

a =
puts "a.var: #{a.var}"
Holder.var = 123
puts "a.var: #{a.var}"

def a.get_var

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
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2009-05-14 07:36
(Received via mailing list)
Can we get the redmine issues fixed?

Begin forwarded message:
This topic is locked and can not be replied to.