On 24.06.2007 04:41, Starke wrote:
> Im trying to set up a method and pass a varible to it then out put the
> new manipulated varible back out.   Here is what I have
> 
> 
> ---------------------------------
> var1 = 'test'
> 
> def change var_in
>   puts var_in
>   var_in = 'test1'
>   puts var_in
> end
> 
> change var1
> 
> -----------------------------------
> 
> As you can see, I pass in var1 into the method and then I change the
> value to 'test1'.

No.  You pass the value of "var1" in, i.e. the object which "var1" 
refers to.  In passing in that value it is assigned to "var_in".  Now 
you have two variables referring the same object.  Then you make 
"var_in" point to another object (your string 'test1').  But "var1" in 
the other scope still points to the original value / object.

>  I would like to method to go back and update var1,
> so that if passed into another method it reflects the change that
> method change var_in did.  Does this make since?  Im new to
> programming.

It may make sense and you can actually do such things in other 
programming languages.  I have never felt the need to do this in Ruby so 
you definitively can live without this feature.  There are a number of 
options you have, two of them have been mentioned in this thread 
(assignment of the return value, instance variables).  Which of those is 
the most appropriate depends on the problem you are trying to solve.  At 
the moment this looks like a solution looking for a problem. :-)

Kind regards

	robert