Topic: Beginner question about integer arrays
Hello
Maybe I'm sitting to long in front of my computer, but I don't see what's wrong here...
I just want to initialize an int Array and add some values to the elements in the array, but it seems that this is completely different to java for example.
def test
te = Array.new(5)
te.each do |t|
t = 10
end
puts "stop"
puts te[0].to_i
puts te[0]
puts "end"
endand the output is:
stop
0
endalthough i would think that the result is 10 at least in one case.
and when i do this:
def test
te = Array.new(5)
te.each do |t|
t = 10
end
te[1] += 100
endthe result is:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.+I hope someone can help me with this basic question...
Regards,
Chang