Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greathmaster/20df3e0691f1fbf738ce66c414070372 to your computer and use it in GitHub Desktop.
Save greathmaster/20df3e0691f1fbf738ce66c414070372 to your computer and use it in GitHub Desktop.
Ruby String references example
#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