This might get some disagreement since some people prefer to distinguish
'values' from 'objects' ...

Everything you manipulate in Ruby is an object.

All variables, method arguments, return values, instance variables, etc.
contain references to these objects. All methods are invoked on an object
via some such reference.

So
    x = y
makes the variable x refer to the same object that the variable y referred
to.

And
    x = a.foo(b)
makes the variable x refer to the object that is returned (as a reference)
by a.foo() when given a parameter that refers to the same object as that
refeerred to by variable b.

When you write
    c_count = 0
your variable c_count _refers_ to the integer object '0'. (Some 'built-in'
objects like integers exist magically, you never explicitly create them; you
just handle references to them).

When you write
    c_count + 1
you are sending the message :+ to the object referred to by c_count i.e.
'0'. This returns a _reference_ to another object, the object '1'.

c_count = c_count + 1
just updates the (parameter) variable c_count so it now refers to object
'1'.

Your external local variable still refers to the object '0'.

Cheers.

"Tookelso" <tookskie-googlegroups / yahoo.com> wrote in message
news:1104823101.584106.327050 / z14g2000cwz.googlegroups.com...
> Hello,
>
> Sorry for asking this basic question, but I couldn't find it in the
> PickAxe book.
>
> When you pass an argument to a method, is it passed by reference, or by
> value?
> Or, does it depend on the object's type?
>
> For example, in the simple script below, the program outputs "0".
> #-----------------------------------
> def test(c_count)
> c_count = c_count + 1
> end
> # begin program
> c_count = 0
> test(c_count)
> puts c_count
> #-----------------------------------
> I realize that for simple things, it's better to return a value from
> the method, but I would like to know *why* it's not modifying my
> "c_count" value.
>
> I'm using ruby 1.8.2 (2004-11-06) [i386-mswin32]
> Thanks in advance,
>
> --Nate
>