Sha256: 49574120687ef14d6cab98ebf3456c03da5fceddda2c8672f023453cd4e442b4

Contents?: true

Size: 309 Bytes

Versions: 1

Compression:

Stored size: 309 Bytes

Contents

class Array
  # Returns positive index of an element
  # based on cardinal positions 1 to n and n to -1.
  #
  #   require 'facet/array/pos'
  #
  #   [1,2,3,4,5].pos(1)   #=> 0
  #   [1,2,3,4,5].pos(-1)  #=> 4
  #
  def pos(i)
    if i > 0
      return i - 1
    else
      self.length + i
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet/array/pos.rb