From: "David A. Black" Date: 2004-07-07T01:28:35+09:00 Subject: Re: Array::index and rindex operator 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.) 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. David -- David A. Black dblack@wobblini.net