Xavier Noria
1/27/2007 6:52:00 PM
On Jan 27, 2007, at 7:29 PM, Austin Ziegler wrote:
> On 1/26/07, Vincent Fourmond <vincent.fourmond@9online.fr> wrote:
>> Andy Koch wrote:
>> > Hello,
>> >
>> > Is there a way to pass variables by reference into function.
>> >
>> > I have large string to pass and the pass by value seems to be
>> eating up
>> > too much memory.
>>
>> You don't actually need to do anything: everything in ruby is
>> passed
>> by reference, (excepted integers, symbols, nil, false and true - am I
>> missing one ?)
>
> Those are still passed by reference. It just so happens that they are
> unique and immutable in the system, so it looks a lot like
> pass-by-value.
I think the problem in these discussions is that "reference" in the
programming language jargon is not the same word as in "pass-by-
reference". This discussion is common in Java forums as well. Java is
pass-by-value.
In C++ since the copy constructor is involved, I found people in
freenode#c++ consider &-arguments to be pass-by-reference because
they can modify the objects in the caller, albeit the assigment test
discussed in the thread does not work, that'd be
def m(b)
b = 7
end
a = 3
m(a)
# a expected to be 7 in pass-by-reference
-- fxn