From: Robert Klemme Date: 2004-07-07T20:47:39+09:00 Subject: Re: Array::index and rindex operator "David A. Black" schrieb im Newsbeitrag news:Pine.LNX.4.44.0407060917190.8001-100000@wobblini... > Hi -- > > On Wed, 7 Jul 2004, Robert Klemme wrote: > > > > > Might be best to just enhance #index with the block variant. > > > > > > What stumped me was: given this: > > > > > > ary.index(x) {|e| } > > > > > > which behavior would you expect? Or would it raise an exception? I > > > couldn't decide which would be best, which is what led me to a new > > > method. > > > > #index simply returns nil. > > I think we're talking about different things. What I meant is: if you > extend/enhance #index to take a block, and then you give it a block > *and* an argument, there's an ambiguity (two possible behaviors): > > a = %w{ a b c d } > i = a.enhanced_index("b") {|x| x == "c" } > > Would i be 1 or 2? Or would it raise an exception, because it's > ambiguous? (It's different from, say, #inject, where there's both an > argument and a block but they have a direct connection with each > other.) I'd certainly have it throw an exception. > My conclusion was that it would be better not to allow this to be > legal, either by enforcing the choice in #index or creating a second > method. Yes, enforce the choice would be my preferred solution. Regards robert