T
Tookelso
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
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