hey folks, perhaps I’m too overtired, but I’ve got an array problem
where I can’t see my error
class Main
$someArray=[]
$someArraytmp=[]
def someMethod(elem,k)
$someArraytmp[k] = elem
if(k==0)
$someArray.push($someArraytmp)
$someArray.each {|e| p e}
end
end
end
t= Main.new
t.someMethod(“hello”, 0)
t.someMethod(“bye”, 0)
From my opinion there must two arrays in the global (array)variable
$someArray.
The first array element should contain a String hello at the first
position.
The second array element (in $someArray) should be a String bye also at
the first position.
So:
$someArray[0]
-> []
-> “hello”
-> []
-> “bye”
But after compiling it there is
$someArray[0]
-> []
-> “bye”
-> []
-> “bye”
can someone explain to me why this happens?
thanx sala