Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created September 25, 2012 00:43
Show Gist options
  • Save havenwood/3779328 to your computer and use it in GitHub Desktop.
Save havenwood/3779328 to your computer and use it in GitHub Desktop.
append vs concat
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