I would like to add an element to an array but without actually changing that array and instead it returning a new one. In other words, I want to avoid:
arr = [1,2]
arr << 3
Which would return:
[1,2,3]
Changing arr itself. How can I avoid this and create a new array?
question from:https://stackoverflow.com/questions/9072689/add-element-to-ruby-array-return-new-array