Module: Jekyll::Nth

Defined in:
nth.rb

Overview

Returns item n of array, origin 1

Instance Method Summary collapse

Instance Method Details

#nth(array, index) ⇒ Object

Returns nth item of an array, origin 1.

Returns:

  • nth item of an array, origin 1



10
11
12
13
14
15
# File 'nth.rb', line 10

def nth(array, index)
  abort 'nth error: array was empty.' if array.nil?
  raise "nth error: array has only #{array.length} items, but item #{index} was requested." if array.length < index.abs

  array[index]
end