Method: Array#pos

Defined in:
lib/nano/array/pos.rb

#pos(i) ⇒ Object

Returns the positive ordinal index given a cardinal position, 1 to n or -n to -1.

[1,2,3,4,5].pos(1)   #=> 0
[1,2,3,4,5].pos(-1)  #=> 4


8
9
10
11
12
13
14
# File 'lib/nano/array/pos.rb', line 8

def pos(i)
  if i > 0
    return i - 1
  else
    self.length + i
  end
end