Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > primeライブラリ > Prime::PseudoPrimeGeneratorクラス > each_with_index

instance method Prime::PseudoPrimeGenerator#each_with_index

with_index {|prime, index| ... } -> self
each_with_index {|prime, index| ... } -> self
with_index -> Enumerator
each_with_index -> Enumerator

与えられたブロックに対して、素数を0起点の連番を渡して評価します。

[RETURN]
ブロックを与えられた場合は self を返します。 ブロックを与えられなかった場合は Enumerator を返します。

例:

Prime::EratosthenesGenerator.new(10).each_with_index do |prime, index|
  p [prime, index]
end
# [2, 0]
# [3, 1]
# [5, 2]
# [7, 3]

[SEE_ALSO] Enumerator#with_index

class Prime::PseudoPrimeGenerator