I'm trying to put an array to another existing array and moreover to put all its items to an existing set. Here's the minimal example:
require "set"
def add(myarr, bigarr, myset)
bigarr << myarr
myset |= Set.new(myarr)
end
bigarr = []
myset = Set.new
add([1, 2], bigarr, myset)
Which yields bigarr = [1, 2]
.. OK, but myset = {}
.. is empty. I know little about passing arguments in Ruby (should be by-value) -- in case of array the value should be a reference to its content, then I have no clue what could be the value of set.
The questions are:
- What is the substantial difference between
Array
andSet
which causes this behavior? - Is there any way to force Ruby pass-by-reference or is there a different recommended way how to solve the problem with referencing?
Thanks in advance!