pass by reference - Ruby passing arguments: difference between Array and Set -
I am trying to put an array in another existing array and with it all its contents in the current set has put. Here's the least example:
To add the requirement of "set" (myarr, bigarr, myset) bigarr & lt; & Lt; Myarr myset | = Set.new (myarr) end bigarr = [] myset = add.new ([1, 2], bigarr, myset) Which yields bigarr = [1 , 2] .. OK, but myset = {} is empty .. I know that there is something to know about passing the arguments in Ruby (value should be value) ) - In the case of the array, the value should be the reference of its contents, then I have no indication what the value of the set can be. The questions are:
- What is the
array and set which is the car of this behavior There is more difference between the tax liability - Is there any way to compel the Ruby pass-by-context or is there a different recommendation in the way with which to solve the problem?
Thanks in advance!
This is nothing to do with the difference between arrays and sets & Lt; You are amending the array with & lt method, but you are assigning the variable with myset . = operator. You never modify the set you have passed. What you probably want to do is myset.merge (myarr) .
Comments
Post a Comment