Created
October 19, 2011 05:05
-
-
Save burtlo/1297511 to your computer and use it in GitHub Desktop.
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
first_array = [ 2, 1, 3] | |
second_array = first_array | |
second_array.sort! | |
puts first_array # [ 1, 2, 3 ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran this by another rubyist out there and my misunderstanding came from the fact that the behavior of the = keyword. My expectation was that if you assign a value to second_array, at line 4 above, because it's all by reference it would change the value referenced by first_array as well. In fact, the = operator appears to create a new pointer and changes the reference of second_array from first_array to whatever you're now pointing it to.