While iterating, I am saving some data to a hash each time. Within the same loop, I push the hash to an array.
The below code does not work, the last hash object overwrites all the other ones in the array.
playlists = []
aPlaylist = {}
while (count < 3)
#some code... produces the hash "aPlaylist"
playlist << aPlaylist
end
The code below does work. Why, and what is the difference?
playlists = []
while (count < 3)
aPlaylist = {}
#some code... produces the hash "aPlaylist"
playlist << aPlaylist
end
Here are the correct and wrong outputs (converted to csv): https://i.stack.imgur.com/wISqj.jpg.