Issue with removing/deleting element from Ruby Array
There is a common dangerous Ruby Array situation when removing/deleting element from Array
a = [1, 2, 3 ]
b = a
b.delete(2)
b
#=> [1, 3]
a
#=> [1, 3] ```
Full explanation why is posted in this article
Solution
a = [1,2,3]
b = a.dup
b.delete(2)
b
# => [1, 3]
a
# => [1, 2, 3]
https://blog.eq8.eu/til/remove-element-from-ruby-array-issue.html
Post a comment