Created
December 27, 2019 23:11
-
-
Save greathmaster/20df3e0691f1fbf738ce66c414070372 to your computer and use it in GitHub Desktop.
Ruby String references example
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
#Ruby string references clarification | |
#Mutation of a string | |
x = "Hello" | |
y = x | |
x << " WORLD" #changing the underlying item in memory | |
puts x #Hello WORLD | |
puts y #Hello WORLD | |
a = "Hello" | |
b = a | |
a += " WORLD" #NOT changing the underlying item in memory | |
puts a #Hello WORLD | |
puts b #Hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment