Add method to Ruby's Enumerable module that produces every nth element
nth slicing

Perhaps you could use a slice with map instead.

module Enumerable
  def nth(n)
    self.each_slice(n).select{|c| c.length == n}.map(&amp;:last)   
  end
end


unit tests

print [2, 4, 6, 8, 10, 12].nth(3) # =&gt; [6, 12]
print "\n"
print [2, 4, 6, 8, 10].nth(3) # =&gt; [6]
print "\n"
print [2, 4, 6, 8].nth(3) # =&gt; [6]
print "\n"
print [2, 4, 6].nth(3) # =&gt; [6]
print "\n"
print [2, 4].nth(3) # =&gt; []
print "\n"




Rubocop Report

Skipping an iteration should be done like this..

 next unless i == relevant_iteration

    ordinal += 1
    relevant_iteration = ordinal * n


rather than..


if i == relevant_iteration
  ordinal += 1
  relevant_iteration = ordinal * n



General Guidelines:


use 2 spaces for indentation
frozen string
n as parameter name: min length should be 3 -> takeIndex instead?


Refactored

# frozen_string_literal: true

module Enumerable
  def nth(takeIndex)
    i = 0
    ordinal = 1
    relevant_iteration = takeIndex * ordinal

    self.select do |num|
      i += 1

      next unless i == relevant_iteration

      ordinal += 1
      relevant_iteration = ordinal * takeIndex

      num
    end
  end
end