On 8/2/06, Chad Perrin <perrin / apotheon.com> wrote:
> On Thu, Aug 03, 2006 at 01:11:35AM +0900, Jacob Fugal wrote:
> >
> > self is not just a memory address (well, not any more than any other
> > object reference). You're seeing the memory address because that's the
> > default #inspect output for an object, but it's not really relevant
> > here. self is an object reference just like any other variable would
> > be. Let's replace the contents of the evals with a method call
> > instead:
> >
> >  # using the same definition of Foo as referenced earlier
> >  foo1, foo2 = Foo.new, Foo.new
> >  foo1.object_id # => 1742734
> >  foo2.object_id # => 1742684
> >
> >  blk1, blk2 = foo1.bar, foo2.bar
> >  eval "object_id", blk1 # => 1742734
> >  eval "object_id", blk2 # => 1742684
> >
> > I also captured the Foo objects themselves so we can see that the
> > object_id method call is being sent to the foo object rather than the
> > block itself.
>
> Are we sure, though, that we're not just looking at a number (associated
> with that instance) that's stored in a hash table external to the
> object?

Actually, object_id is calculated from the reference itself.
Simplified, it's pretty similar to the memory reference itself. But
the point is, while the memory reference may be the source of the
value, we're retrieving it through a method call. The fact that I'm
making a method call implies that we have a reference to an object
call that method against. The choice of object_id as that method is
just convenience to show that the objects referred to are at once
unique from each other, and identical to the source objects.

Jacob Fugal