Skip to content

Instantly share code, notes, and snippets.

@disolovyov
Created October 28, 2010 07:07
Show Gist options
  • Save disolovyov/650814 to your computer and use it in GitHub Desktop.
Save disolovyov/650814 to your computer and use it in GitHub Desktop.
Copy and append vs append
# Copy and append
s1 = 'hey'
s2 = s1
s1 += 'hi' # Two new string objects are created: 'hi' and the result of s1 + 'hi'
puts s1 # heyhi
puts s2 # hey
# Append
s3 = 'hey'
s4 = s3
s3 << 'hi' # One new string object is created: 'hi'
puts s3 # heyhi
puts s4 # heyhi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment