title: Ruby passing arguments: difference between Array and Set
body: <p>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:</p>
  
  <pre><code>require "set"
  
  def add(myarr, bigarr, myset)
      bigarr &lt;&lt; myarr
      myset |= Set.new(myarr)
  end
  
  bigarr = []
  myset = Set.new
  
  add([1, 2], bigarr, myset)
  </code></pre>
  
  <p>Which yields <code>bigarr = [1, 2]</code> .. OK, but <code>myset = {}</code> .. 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. </p>
  
  <p>The questions are:</p>
  
  <ol>
  <li>What is the substantial difference between <code>Array</code> and <code>Set</code> which causes this behavior?</li>
  <li>Is there any way to force Ruby pass-by-reference or is there a different recommended way how to solve the problem with referencing?</li>
  </ol>
  
  <p>Thanks in advance!</p>