Sha256: a939d119929033fa1c0931cec5f884559670a94bea0f75a47f8524df8a1762d6
Contents?: true
Size: 585 Bytes
Versions: 26
Compression:
Stored size: 585 Bytes
Contents
class Array # 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 # def pos(i) if i > 0 return i - 1 else self.length + i end end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCArray < Test::Unit::TestCase def test_pos a = [1,2,3,4,5] assert_equal( 0, a.pos(1) ) assert_equal( 4, a.pos(-1) ) end end =end
Version data entries
26 entries across 26 versions & 1 rubygems