it works correctly, type of the $.
variable is Integer
puts $..class. # => Integer
So right side of the addition will be casted to the Integer
.
In first case 1r
is casted to the Integer
of value 1
, so you can see value is changing.
In second case 1r/2
is casted to the Integer of value 0
, so you don't see changes because adding zero will not change original value.
You can not change type of pre-defined global variable, just try $. = "text"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…