Module: ArrayManipulation

Defined in:
lib/jekyll_nth.rb

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



13
14
15
16
17
18
# File 'lib/jekyll_nth.rb', line 13

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

  array[index]
end

#tail(array) ⇒ Object



20
21
22
23
24
# File 'lib/jekyll_nth.rb', line 20

def tail(array)
  abort "jekyll_nth error: array passed to tail was empty." if array.nil? || array.empty?

  array[1..]
end