This confuses me:
irb(main):001:0> h = {}
=> {}
irb(main):002:0> t = [ 1, 2, 3]
=> [1, 2, 3]
irb(main):003:0> h[“f”] = t
=> [1, 2, 3]
irb(main):004:0> t += [ 4, 5, 6 ]
=> [1, 2, 3, 4, 5, 6]
irb(main):005:0> t
=> [1, 2, 3, 4, 5, 6]
irb(main):006:0> h[“f”]
=> [1, 2, 3]
irb(main):007:0>
I thought h[“f”] held a reference to the object t so if t changed, so
would h[“f”].
I’m using Ruby 2.0.0p247 (Also tested on 1.8.7 so obviously I’ve been
confused the whole time.)
What confuses me is this implies that the assignment of h[“f”] is making
a copy of t at the time of the assignment.