Ruby 2.6.0 リファレンスマニュアル > ライブラリ一覧 > primeライブラリ > Prime::PseudoPrimeGeneratorクラス > each_with_index
with_index {|prime, index| ... } -> self
[permalink][rdoc]each_with_index {|prime, index| ... } -> self
with_index -> Enumerator
each_with_index -> Enumerator
与えられたブロックに対して、素数を0起点の連番を渡して評価します。
require 'prime'
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