From: Robert Klemme Date: 2004-09-19T20:59:58+09:00 Subject: Re: Array#index block and rdetect "trans. (T. Onoma)" schrieb im Newsbeitrag news:200409190606.22327.transami@runbox.com... > Tiny RCR suggestion: > > Array#index optionally take a block like Enumerable#detect does. > > ['a','b','c'].index{|e| e == 'b'} # => 1 > ['a','b','c'].index{|e| e == 'c'} # => 2 > ['a','a','a'].index{|e| e == 'a'} # => 0 > ['a','a','a'].index{|e| e == 'b'} # => nil > > Question: why isn't #index a method of Enumerable, considering > #each_with_index is? (FYI: 'alias find detect'.) Because not all collections keep a definite order as Array does. For example, hashes do not keep any certain order of elements hence indexing does not make any sense. > Lastly, what about an rdetect? Not in Enumerable because each only iterates in one direction. (Ok, you could go through it an output the last but that would not work for Enumerables that return infinite elements.) Regards robert