E
E
eldar_web2015-12-05 14:19:15
ruby
eldar_web, 2015-12-05 14:19:15

How to assign one array to another in Ruby (so that they are different objects)?

There are for example arrays:
list = [1,2,3]
I create an array list2 =[] I
assign list2 << list
I delete an element from the array list2.delete(1)
This element is also deleted in list.
As I understand it, you need to use Marshal.dump here, but I tried it - it doesn't work.
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
inapped, 2015-12-05
@eldar_web

list2 = Array.new(list)
as an option

D
Dima, 2015-12-05
@MAXOPKA

list2 = list.dup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question