Created
September 25, 2012 00:43
-
-
Save havenwood/3779328 to your computer and use it in GitHub Desktop.
append vs concat
This file contains 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
string = 'hi' | |
# => "hi" | |
string.object_id | |
# => 67890 | |
string.object_id # yup, same every time | |
# => 67890 | |
string << ' you' | |
# => "hi you" | |
string.object_id | |
# => 67890 | |
## ^ Look, same object_id, so same Object as the original String with #<< | |
string = 'hi' | |
# => "hi" | |
string.object_id | |
# => 40572 | |
string.object_id # still same every time | |
# => 40572 | |
string += ' you' | |
# => "hi you" | |
string.object_id # OMGWTFBBQ | |
# => 12345 | |
## ^ Brand new Object with #+= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment