Tookelso <tookskie-googlegroups / yahoo.com> wrote:
> 
> When you pass an argument to a method, is it passed by reference, or by
> value?

Passed by reference to an object.

> For example, in the simple script below, the program outputs "0".
> #-----------------------------------
> def test(c_count)
> c_count = c_count + 1

This creates a new object, gives it the value c_count+1 and has the
c_count variable point to it.

Try the following:

def test1(str)
  str = str.upcase
end

def test2(str)
  str.upcase!
end

a = "hello"
b = "world"
puts test1(a) #=> HELLO
puts test2(b) #=> WORLD
puts a #=> hello
puts b #=> WORLD

In test1, the variable is pointed to a new object. In test2, the object
to which the variable points is modified via one of its 'destructive'
methods. In general, unless an object provides a mutation method, you
can't change it this way.

Note that the *variable* is local to the method body, and doesn't change
which object the outside variable refers to.

martin