From: Joel VanderWerf Date: 2004-01-27T08:29:17+09:00 Subject: Re: def foo[](x) Gavin Kistner wrote: ... > 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] Your rule above, as I read it, would resolve the ambiguity: @beernuts[0]. Trying #bar[] before #bar, as you propose, makes sense because if you really want #bar, you can easily force it with parens: (x.bar)[0], whereas there's no way to force #bar[], short of using #send. But what I had in mind was something involving inheritance: class Base def bar[](x) "base" end end class Sub < Base def bar(x) ["sub"] end end Sub.new.bar[0] Would this return "base" or "sub"?