Skip to content

Instantly share code, notes, and snippets.

@EmilReji
EmilReji / part1.rb
Created February 25, 2019 00:57
Nested Data Structures Shallow Copy Question
arr1 = ["a", "b", "c"]
arr2 = arr1.dup
p arr1.object_id
p arr2.object_id
p arr1.object_id == arr2.object_id # false
p arr1[0].object_id
p arr2[0].object_id
p arr1[0].object_id == arr2[0].object_id # true
arr2.map! do |char|
char.upcase