Created
February 12, 2016 14:37
-
-
Save sdball/73e673909092b135ace1 to your computer and use it in GitHub Desktop.
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
original = [ | |
{ a: { foo: 1 } }, | |
{ b: { foo: 2 } }, | |
{ c: { foo: 3 } }, | |
{ d: { foo: 4 } }, | |
{ e: { foo: 5 } }, | |
{ f: { foo: 6 } }, | |
{ g: { foo: 7 } }, | |
] | |
copy = original.each do |item| | |
item.each do |k, v| | |
v[:foo] = v[:foo] + 1 | |
end | |
end | |
p copy | |
# [{:a=>{:foo=>2}}, {:b=>{:foo=>3}}, {:c=>{:foo=>4}}, {:d=>{:foo=>5}}, {:e=>{:foo=>6}}, {:f=>{:foo=>7}}, {:g=>{:foo=>8}}] | |
p original | |
# [{:a=>{:foo=>2}}, {:b=>{:foo=>3}}, {:c=>{:foo=>4}}, {:d=>{:foo=>5}}, {:e=>{:foo=>6}}, {:f=>{:foo=>7}}, {:g=>{:foo=>8}}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment