Array.new(4, Point.new)
will create an array with the same object (in this case an instance of Point).
my_square = Array.new(4, Point.new)
p my_square.map(&:object_id).uniq.count
#=> 1
If you change to Array.new(4) { Point.new }
, this will populate array with different objects.
my_square = Array.new(4) { Point.new }
p my_square.map(&:object_id).uniq.count
#=> 4
Check this for more info.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…