From: Jim Weirich Date: 2009-02-26T13:59:56+09:00 Subject: [ruby-core:22533] Re: YASNP (Yet Another Selector Namespace Proposal) On Feb 25, 2009, at 10:28 PM, Gary Wright wrote: >> Which namespaces? The ones in scope at the original call site, or >> the ones in scope at the super invocation? > > My first thought was the one in scope at the original call site. > I'll have to think harder about what it would mean for a different > set of namespaces to be in play at the super invocation than at the > original call site. Here's a concrete example of why super searching namespaces at the original call site is probably not what you want. ------------------------------------ module WebCam include Camera def shoot super # line 4 end end module Gun def shoot super # line 10 end end using WebCam for Object # I'm assuming WebCam takes precedence using Gun for Object obj = Object.new # The following calls WebCam#shoot obj.shoot # line 20 ------------------------------------ WebCam#shoot gets invoked (because as the first namespace it gets precedence[1]), which in turn calls super at line 4. If super searches namespaces from the original call site (line 20), there is a good chance that Gun#shoot would be called[2]. I would suggest that having WebCam#shoot invoke Gun#shoot via super is a less than optimal outcome. If instead, the super call on line 4 only continued the chain with namespaces available at line 4, then the Camera#shoot method would be called. This outcome makes much more sense. Methods invoking super need to be designed to work together (at least to some degree[3]). Namespaces are for keeping unrelated methods from colliding. Having super search namespaces from the original call site will mix unrelated methods. Does this make sense? -- -- Jim Weirich -- jim.weirich@gmail.com [1] I'm not sure we have decided formally which one gets precedence. Charlie indicate the first one would so I'm using that in the example. [2] It doesn't matter if Gun#shoot or Camera#shoot are called next in the chain. If each shoot method keeps invoking super and they all go back to the original call site, then eventually all versions of shoot will be called. [3] They need to work together as far as conforming to the same pre/ post conditions contract, i.e. the "require no more, promise no less" mantra of design by contract.