On 10/24/07, David A. Black <dblack / rubypal.com> wrote:
> Hi --
>
> On Thu, 25 Oct 2007, Todd Benson wrote:
>
> > On 10/24/07, Todd Benson <caduceass / gmail.com> wrote:
> > Okay, I guess I can answer my own question.  Binding is resolved when
> > an operator like '=' is interpreted, especially with immutable objects
> > (like Fixnum).
> >
> > a = 1,2,3
> > puts a[0].__id__
> > #output => 3
> > b = a
> > puts b.__id__
> > #output => 3
> > a[0] = 7
> > puts a[0].__id__
> > #output => 15
> > puts b.__id__
> > #output => 3
> >
> > For the newbies out there, keep this in mind.  The name b put on
> > a[0]'s shoes and kept them on.  Somebody correct me if I'm wrong.
>
> I'm not seeing what you're seeing:
>
> irb(main):014:0> a = 1,2,3
> => [1, 2, 3]
> irb(main):015:0> a[0].__id__
> => 3
> irb(main):016:0> b = a
> => [1, 2, 3]
> irb(main):017:0> b.__id__
> => 1669980                # Are you really seeing 3 here?
> irb(main):018:0> a[0] = 7
> => 7
> irb(main):019:0> a[0].__id__
> => 15
> irb(main):020:0> b.__id__
> => 1669980                # And here?
>
> When you do b = a, you're binding b to the same object as a. I don't
> know why b would think you had bound it to a[0].
>
>
> David
>

You're right David.  That was supposed to be b = a[0] and _not_ b = a.

Todd