Self as method argument revisited

From: dblack@candle.superlink.net [mailto:dblack@candle.superlink.net]

A while ago transami brought up the question of an object needing
access to the object that created it, and there was discussion of
techniques including sending self as an argument.

I had my first Ruby epiphany when I was working on a netlisting
tool where I needed to be able to traverse the hierarchy in
both directions. When I wrote the following line of code in the
“add a new block to the hierarchy” method:

child.parent = self

the profound, fundamental truth of that statement – as bad of a
programmer that I might be – let me know that I was doing something
right. :^)

Cheers,

  • jeff

“Gray, Jeff” jeff.gray@intel.com writes:

From: dblack@candle.superlink.net [mailto:dblack@candle.superlink.net]

A while ago transami brought up the question of an object needing
access to the object that created it, and there was discussion of
techniques including sending self as an argument.

I had my first Ruby epiphany when I was working on a netlisting
tool where I needed to be able to traverse the hierarchy in
both directions. When I wrote the following line of code in the
“add a new block to the hierarchy” method:

child.parent = self

the profound, fundamental truth of that statement – as bad of a
programmer that I might be – let me know that I was doing something
right. :^)

Cheers,

  • jeff

We’re lucky that Ruby doesn’t also have a “spouse” keyword, or else then
there would be ambiguity, since the following would also be true:

child.parent = spouse

:slight_smile:

···


Lloyd Zusman
ljz@asfast.com

Now you’re talking multiple inheritance.
Or genetic algorithms. :slight_smile:

Hal

···

----- Original Message -----
From: “Lloyd Zusman” ljz@asfast.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, September 23, 2002 7:23 PM
Subject: Re: self as method argument revisited

“Gray, Jeff” jeff.gray@intel.com writes:

From: dblack@candle.superlink.net [mailto:dblack@candle.superlink.net]

A while ago transami brought up the question of an object needing
access to the object that created it, and there was discussion of
techniques including sending self as an argument.

I had my first Ruby epiphany when I was working on a netlisting
tool where I needed to be able to traverse the hierarchy in
both directions. When I wrote the following line of code in the
“add a new block to the hierarchy” method:

child.parent = self

the profound, fundamental truth of that statement – as bad of a
programmer that I might be – let me know that I was doing something
right. :^)

Cheers,

  • jeff

We’re lucky that Ruby doesn’t also have a “spouse” keyword, or else then
there would be ambiguity, since the following would also be true:

child.parent = spouse

:slight_smile: