Passing array to ruby function
<p>Okay, I got confused by how ruby passes it's arguments to a function. I've read in the documentation that ruby passes by <strong>value</strong>, but in my case it looks like it's passing by <strong>referance</strong>
Here's the problem:</p>

<pre><code>def buble_sort(arr) 
unordered = true
while unordered
    unordered = false
    for i in (1..arr.size-1)
        if(arr[i-1] &gt; arr[i])
            arr[i-1], arr[i] = arr[i], arr[i-1] 
            unordered = true;
        end
    end
end
arr
end
</code></pre>

<p>Calling this method shouldn't modify the arr value, since ruby passes it by value. But in my case, it <strong>does</strong> modify the original array. Why?
Code:</p>

<pre><code>p "#{arr} before sort" # =&gt; "[85, -4, 1, 2, 55, 23, 0] before sort"
p buble_sort(arr) # =&gt; [-4, 0, 1, 2, 23, 55, 85]
p "#{arr} after sort" # =&gt; "[-4, 0, 1, 2, 23, 55, 85] after sort"
</code></pre>