with_index {|prime, index| ... } -> selfRuby 1.9.3 から[permalink][rdoc][edit]each_with_index {|prime, index| ... } -> selfwith_index -> Enumeratoreach_with_index -> Enumerator-
与えられたブロックに対して、素数を0起点の連番を渡して評価します。
- [RETURN]
- ブロックを与えられた場合は self を返します。 ブロックを与えられなかった場合は Enumerator を返します。
require 'prime' Prime::EratosthenesGenerator.new.each_with_index do |prime, index| break if prime > 10 p [prime, index] end # => [2, 0] # [3, 1] # [5, 2] # [7, 3][SEE_ALSO] Enumerator#with_index