From: Dossy Date: 2002-07-10T01:22:08+09:00 Subject: Re: self_parent On 2002.07.09, Tom Sawyer wrote: > > essentially what i am trying to create are non-bound, or open, Proc > objects, in contrast to the type of Proc objects we can create now, > which are bound to the local variables at the time of creation. I want > Proc objects that get bound at the time of calling: > > class A > def initialize(x) > x.call > end > def display > puts 'hello' > end > end > > class B > def initialize(x) > x.call > end > def display > puts 'goodbye' > end > end > > x = OpenProc { display } > > A.new(x) --> hello > B.new(x) --> goodbye > > in this way an object can, in effect, ask another object what it should > do. and that is what i was accomplishing, albiet in a lame way, by > passing self (and wanting self_parent for). > > so, is there any way to readily accomplish this in ruby? You said you didn't want to pass self, but given your example this is what I would do: class A def initialize(k) k.call(self) end def display puts 'hello' end end class B def initialize(j) j.call(self) end def display puts 'goodbye' end end y = lambda { |z| z.display } A.new(y) B.new(y) Is there a slightly more detailed example that might better illustrate what you're trying to do? -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)