Topic: Beginner question about integer arrays
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.to_i puts te puts "end" end
and the output is:
stop 0 end
although 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 += 100 end
the 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...