Skip to content

Instantly share code, notes, and snippets.

@sagevann
Created October 19, 2011 18:57
Show Gist options
  • Save sagevann/1299306 to your computer and use it in GitHub Desktop.
Save sagevann/1299306 to your computer and use it in GitHub Desktop.
Array by Reference?
v = [ 1, 2, 3 ]
b = v
b = [ 2, 3, 4 ]
puts v
# expected output [ 2, 3, 4] actual output [ 1, 2, 3]
# in this case it appears that the [ ] operator does not overwrite the values in the
# array v as I would expect
v = [ 2, 5, 3 ]
b = v
b.sort!
puts v
# output is [ 2, 3, 5 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment