On Sat, 14 Jun 2003 08:01:40 +0900
Rasputin <rasputin / shrike.mine.nu> wrote:

> * Jason Creighton <androflux / remove.to.reply.softhome.net> [030612 19:44]:
> > On Thu, 12 Jun 2003 23:14:37 +0900
> > Rasputin <rasputin / shrike.mine.nu> wrote:
> > 
> > > > remember that pretty much everything is a reference and you won't go
> > > > far wrong
> > > 
> > > I thought so, until this happened!
> > > The array was full of references, so I thought el held the
> > > reference from the Array.
> > > 
> > > It seems to hold a copy of the reference...
> > 
> > No, it doesn't. When you do a:
> > 
> > a = "Hello world, nice to meet you!".split(' ')
> > a.each { |word| word = "lala" }
> > p a
> > ["Hello", "world,", "nice", "to", "meet", "you!"]
> > 
> > You're binding word to a different object, not changing the objects
> > themselves. If you did this:
> 
> By 'copy of the reference' I meant:
> 
> ary = %w( a b c d e)
> ary.each { |r| r = "X" }
> 
> r is given a copy of the 'reference' (apology for the Perlism),
> so when you point (ugh, and the Cism) r at "X" you're updating a
> copy of the reference, not the original reference. Is that about right?

Yes, that's about right. If the following code makes sense, then you probably
understand what's going on.

ary = %w(a b c d e)         # => ["a", "b", "c", "d", "e"]
x = ary[0]                  # => "a"
ary[0].id                   # => 537767284
x.id                        # => 537767284
x = "X"                     # => "X"
x.id                        # => 537766974
ary                         # => ["a", "b", "c", "d", "e"]

Jason Creighton