I have the following code:
session={"apple"=>["bp", "80APPM", "donald"]}
@like_list = session
@like_list.each do |key, value|
value.each_with_index do |v, i|
@like_list[key][i] = 2
end
end
session # => {"apple"=>[2, 2, 2]}
@like_list # => {"apple"=>[2, 2, 2]}
The object assigned to the variables session
and @like_list
are both changed. Is there any way to perform the above code without changing the value of session
?
I tried using clone
and dup
but no change