Skip to content

Instantly share code, notes, and snippets.

@1dolinski
Created April 15, 2013 13:00
Show Gist options
  • Select an option

  • Save 1dolinski/5387887 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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