From: Gavin Kistner Date: 2004-01-27T08:14:53+09:00 Subject: Re: def foo[](x) Joel VanderWerf wrote: >> I'm glad I'm not the only one. I have now added this as an RCR: >> http://www.wobblini.net/rcr/RCR/RCR201 > > > Question: in this method call: > > x.foo[1] > > what is the search order? First for #foo, and then for #foo[]? Or the > other way around? I addressed this in the RCR. Currently the following are equivalent: x.foo[1] (x.foo)[1] (x.foo)[](1) I propose that it try: x.foo[](1) first, and if that method does not exist, then default to the current: (x.foo)[](1) > Suppose it's #foo, then #foo[]. What if #foo is implemented in the > superclass, but #foo[] is implemented in the class of x itself? In other > words, depth-first search or breadth-first search? Hrm...this is a good point. You're saying that with the following, the syntax would allow both, but there would be ambiguity: class Foo def initialize @beernuts=[] @peanuts=[] end def bar return @peanuts end def bar[](x) return @beernuts[x] end end x = Foo.new puts x.bar[0] #Is this @peanuts[0] or @beernuts[0] Adding both would be foolish as a developer (perhaps even throwing a warning about them at compile time), but as long as the search order was clearly defined, I personally wouldn't be too worried.