Skip to content

Instantly share code, notes, and snippets.

@1dolinski
Created April 15, 2013 13:00
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 1dolinski/5387887 to your computer and use it in GitHub Desktop.
Save 1dolinski/5387887 to your computer and use it in GitHub Desktop.
w = [[2],[1],[3]]
#=> [[2], [1], [3]]
x = w.dup
#=> [[2], [1], [3]]
x.each do |a|
a << 1
end
[12] pry(main)> x
#=> [[2, 1], [1, 1], [3, 1]]
[13] pry(main)> w
#=> [[2, 1], [1, 1], [3, 1]]
@1dolinski
Copy link
Author

Why is this manipulating the original object?

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