Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisbloom7/329281 to your computer and use it in GitHub Desktop.
Save chrisbloom7/329281 to your computer and use it in GitHub Desktop.
The hardest thing for me to grok in Ruby
colors = ["red"] #=> ["red"]
colors_2 = colors #=> ["red"]
colors_2 << "blue" #=> ["red", "blue"]
colors #=> ["red", "blue"]
def add_white (original_colors)
original_colors << "white"
end
add_white colors #=> ["red", "blue", "white"]
colors_2 #=> ["red", "blue", "white"]
@chrisbloom7
Copy link
Author

TL;DR: hashes have some sharp edges because depending on assignment it is possible for them to mutate out from under you as you pass them around. It is also possible for them not to mutate out from under you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment