From: Ryan Davis Date: 2009-05-14T14:36:13+09:00 Subject: [ruby-core:23448] Fwd: Bug report involving class variables Can we get the redmine issues fixed? Begin forwarded message: > From: Ken Ballou > Date: May 13, 2009 4:24:41 PM PDT > To: ruby-talk@ruby-lang.org (ruby-talk ML) > Subject: Bug report involving class variables > Reply-To: ruby-talk@ruby-lang.org > X-Spam-Status: No, score=-2.6 required=5.0 > tests=BAYES_00,RCVD_IN_DNSWL_LOW, ZSS_RUBY autolearn=ham > version=3.2.5-zss_spam_1_1_1 > > (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) > [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 >