Hi --

On Mon, 8 Dec 2003, nainar wrote:

>  However , I am still puzzled by the rules about function parameters.
>  Perl and Python  both permit you to alter the original variable, or
>  work on copies of the variables inside function( as required by the
>  program logic).In Ruby, outside a function an assignments and modification
>  act the way you expect it to.Why should they behave differently inside a
>  function?

They don't; it's exactly the same.  The best way to think of it is
that when you call a method with arguments, what takes place is
assignment:

   def meth(x,y)
     puts x + y
   end

   meth(3,4)

   # what happens is:
   #
   #  x = 3
   #  y = 4


   s = "hi"
   t = " there"
   meth(s,t)

   #  x = s
   #  y = t


In that second case, the one with variables, once the implicit
assignment happens, x and y behave exactly like s and t.  There's no
special case, no special behavior.

   def meth2(x,y)
     x << y
   end

   s = "hi"
   t = " there"
   meth2(s,t)
   puts s         # "hi there"


David

-- 
David A. Black
dblack / wobblini.net