require ‘p’
lol = {}
lol[:arr] = []
puts “#{lol[:arr].class} obj_id=#{lol[:arr].object_id}”
lol[:arr] + [Task.new(:id => ‘id01’)]
pp lol
puts “#{lol[:arr].class} obj_id=#{lol[:arr].object_id}”
lol[:arr] + [Task.new(:id => ‘id02’)]
pp lol
puts “#{lol[:arr].class} obj_id=#{lol[:arr].object_id}”
lol[:arr] + [Task.new(:id => ‘id03’)]
pp lol
puts “#{lol[:arr].class} obj_id=#{lol[:arr].object_id}”
Produces:
Array obj_id=23293860
{:arr=>[]}
Array obj_id=23293860
{:arr=>[]}
Array obj_id=23293860
{:arr=>[]}
Array obj_id=23293860
—What does it mean? Nothin has been added
lol = {}
lol[:arr] = []
lol[:arr] << Task.new(:id => ‘id01’)
pp lol
lol[:arr] << Task.new(:id => ‘id02’)
pp lol
lol[:arr] << Task.new(:id => ‘id03’)
pp lol
Produces:
{:arr=>[Task[|id => id01|]]}
{:arr=>[Task[|id => id02|], Task[|id => id02|]]}
{:arr=>[Task[|id => id03|], Task[|id => id03|], Task[|id => id03|]]}
—Why does each insertion replaces each elem in array?
!!!but!!!
arr = []
arr << Task.new(:id => ‘id01’)
pp arr
arr << Task.new(:id => ‘id02’)
pp arr
arr << Task.new(:id => ‘id03’)
pp arr
produces:
[Task[|id => id01|]]
[Task[|id => id02|], Task[|id => id02|]]
[Task[|id => id03|], Task[|id => id03|], Task[|id => id03|]]
—it’s ok…