0

I have the following code:

vara=[{:command=>"a"},{:command=>"b"},{:command=>"c"}]
varb=vara.clone
varb.each do |var|
  var[:command] = "d"
end
puts vara

I've also tried using:

varb=vara.dup

the result i get is:

{:command=>"d"}
{:command=>"d"}
{:command=>"d"}

how can i adjust this so my vara has the original data i entered in the top of the script?

  • See the second answer in [Cloning an array with its content](https://stackoverflow.com/questions/31455309/cloning-an-array-with-its-content/46839590#46839590) – ggorlen Jun 16 '21 at 17:02

0 Answers0