Bug report involving class variables

(Slight rant: I tried to submit this bug report through the tracker
system at 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)

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 = Holder.new
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

Can we get the redmine issues fixed?

Begin forwarded message:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs