hash = Hash.new
%w(cat dog wombat).each_with_index {|item, index|
hash[item] = index
}
hash #=> {"cat"=>0, "dog"=>1, "wombat"=>2}
RubyDoc の例
10 万個のオブジェクトのコレクションを反復処理する必要があります。通常は find_each を実行しますが、この場合はインデックスも必要です。独自のインデックスを作成できますが、この場合の rubyism があるかどうか疑問に思っていました。
collection.find_each_with_index のようなものが欲しい
ありがとう