Subject: Re: Passing script input as method args always global?
	Date: mer 13 nov 13 12:23:22 +0000

Quoting gvim (gvimrc / gmail.com):

> In your example a and b are mutated but in mine x remains unchanged.

Because in your method:

> def f(y)
>   y = y + 1
>   return y
> end

you receive an object, but you return another one. The fact that it is
still called 'y' (within your local method) does not insure that it is
the same thing.

Thus, the original object is indeed unchanged. 

This is because the implementators of the sum of the Numeric class
decided that it was appropriate to return a new object when performing
a sum. 

If you go back to my previous example, and substitute the plus method
so that instead of 

  def +(new_v)
    @v+=new_v
    self
  end

it reads

  def +(new_v)
    Tally::new(@v+new_v)
  end

(note that I changed the name of the local variable so that things may
be easier to understand), then you will still have 

puts f(var)   #=> 3
puts var      #=> 2

Carlo

-- 
  *         Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido / fluido.as             che bisogno ci sarebbe
  *               di parlare tanto di amore e di rettitudine? (Chuang-Tzu)