Call-by-reference problem again

I think it is explained already in the discussion. I am clear now, but I
still think it is different. Because if you do this:

a=b=c=d=e=“hello”
a=“world”

Then, b, c, d, e, won’t be changed.

Shannon

···

From: Mauricio Fernández batsman.geo@yahoo.com
Reply-To: ruby-talk@ruby-lang.org
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: Re: call-by-reference problem again
Date: Tue, 3 Dec 2002 17:31:00 +0900

On Tue, Dec 03, 2002 at 08:18:39AM +0900, Shannon Fang wrote:

Hi,

I modified my code, I’m afraid that I can’t find it. It is like the
following:

class MailInfo
def initialize
@path=@recipients=@from=Array.new

end
def parse
case header
when “TO”, “CC”, “BCC”
@recipients << header
when “RECEIVED”
@path << header
end
end

end

in the above code, the arrays will interfere with each other. The way to
solve it is not to use chained assignment.

Yes, because they are all the same array :slight_smile:
But why is it any different from String(s)?


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Linux - Das System fuer schlaue Maedchen :wink:
– banshee


STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail

That’s no different than:

a=b=c=d=e=[1, 2, 3]
a=[4, 5, 6]

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.03 at 07.52.23

···

On Tue, 3 Dec 2002 18:19:27 +0900, Shannon Fang wrote:

I think it is explained already in the discussion. I am clear now,
but I still think it is different. Because if you do this:

a=b=c=d=e=“hello”
a=“world”

Then, b, c, d, e, won’t be changed.

I think it is explained already in the discussion. I am clear now,
but I still think it is different. Because if you do this:

But it is not! :slight_smile:

a=b=c=d=e=“hello”
a=“world”

Then, b, c, d, e, won’t be changed.

That’s no different than:

a=b=c=d=e=[1, 2, 3]
a=[4, 5, 6]

That’s my point. There’s nothing special about Array in Ruby… but the
’ notation which is just syntactic sugar anyway.

···

On Tue, Dec 03, 2002 at 09:53:29PM +0900, Austin Ziegler wrote:

On Tue, 3 Dec 2002 18:19:27 +0900, Shannon Fang wrote:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Software is like sex; it’s better when it’s free.
– Linus Torvalds