I cannot understand this ruby behavior, the code explains better what I mean:
class DoNotUnderstand
def initialize
@tiny_array = [3,4]
test
end
def messing(ary)
return [ary[0]+=700, ary[1]+=999]
end
def test
puts @tiny_array.join(",") # before => 3,4
messing(@tiny_array)
puts @tiny_array.join(",") # after => 703,1003
end
end
question = DoNotUnderstand.new
@tiny_array
was [3,4]
and became [703,1003]
if I don't use a class, that happens:
@tiny = [1,2]
def messing(ary)
return [ary[0]+693,ary[1]+999]
end
puts @tiny.join(",") # before => 1,2
messing(@tiny)
puts @tiny.join(",") # after => 1,2
the array simply remains [1,2]
why?