Created
October 19, 2011 18:57
-
-
Save sagevann/1299306 to your computer and use it in GitHub Desktop.
Array by Reference?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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