Skip to content

Instantly share code, notes, and snippets.

@arturoherrero
Last active April 25, 2016 15:59
Show Gist options
  • Save arturoherrero/9984405d559f50a12e530dcaeb7ba706 to your computer and use it in GitHub Desktop.
Save arturoherrero/9984405d559f50a12e530dcaeb7ba706 to your computer and use it in GitHub Desktop.
Comparing Array.push, Array.concat and Array.+= Ruby behaviour
a = [1,2,3] # => [1, 2, 3]
b = [4,5] # => [4, 5]
a.object_id # => 70128600052080
a += b # => [1, 2, 3, 4, 5]
[a, b] # => [[1, 2, 3, 4, 5], [4, 5]]
a.object_id # => 70128599818940
a = [1,2,3] # => [1, 2, 3]
b = [4,5] # => [4, 5]
a.object_id # => 70128600052080
a += b # => [1, 2, 3, 4, 5]
[a, b] # => [[1, 2, 3, 4, 5], [4, 5]]
a.object_id # => 70128600052080
a = [1,2,3] # => [1, 2, 3]
b = [4,5] # => [4, 5]
a.object_id # => 70128600052080
a += b # => [1, 2, 3, 4, 5]
[a, b] # => [[1, 2, 3, 4, 5], [4, 5]]
a.object_id # => 70128600052080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment