Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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