B
Bob Gustafson
I seem to have uncovered a bug. The program below defines a series of
variables, named constant, modify, and variable. The constant should
remain constant, but instead, it changes - even without an assignment.
How does this happen?
[root@hoho4 ocr]# cat test.rb
constant = '31.12.2006'
puts "constant " + constant
modify = '40.01'
puts "modify " + modify
variable = constant
puts "variable " + variable
puts "constant " + constant
variable[0..1] = modify[0..1]
puts "variable " + variable
puts "constant " + constant
[root@hoho4 ocr]# ruby test.rb
constant 31.12.2006
modify 40.01
variable 31.12.2006
constant 31.12.2006
variable 40.12.2006
constant 40.12.2006 <<<---- Why does this change???
[root@hoho4 ocr]# ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux]
variables, named constant, modify, and variable. The constant should
remain constant, but instead, it changes - even without an assignment.
How does this happen?
[root@hoho4 ocr]# cat test.rb
constant = '31.12.2006'
puts "constant " + constant
modify = '40.01'
puts "modify " + modify
variable = constant
puts "variable " + variable
puts "constant " + constant
variable[0..1] = modify[0..1]
puts "variable " + variable
puts "constant " + constant
[root@hoho4 ocr]# ruby test.rb
constant 31.12.2006
modify 40.01
variable 31.12.2006
constant 31.12.2006
variable 40.12.2006
constant 40.12.2006 <<<---- Why does this change???
[root@hoho4 ocr]# ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux]