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:

  1. What is the array and set which is the car of this behavior There is more difference between the tax liability
  2. 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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -