Sha256: 526a9ea7e9d219fbebadc48a65c93bd89a8ba9169996ae578ae2b96a88a59c61
Contents?: true
Size: 1.16 KB
Versions: 25
Compression:
Stored size: 1.16 KB
Contents
class Array # Like #first but returns the first element # in a new array. # # [1,2,3].head #=> [1] # def head slice(0,1) end # Returns an array from second element to last element. # # [1,2,3].tail #=> [2,3] # def tail slice(1,length-1) end # Like #last, returning the last element # in an array. # # [1,2,3].foot #=> [3] # def foot slice(-1,1) end # Returns an array of the first element upto, # but not including, the last element. # # [1,2,3].body #=> [1,2] # #-- # Better name for this? (bulk, perhaps?) #++ def body slice(0,length-1) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCArray < Test::Unit::TestCase def test_head a = [1,2,3,4,5] assert_equal( [1], a.head ) end def test_tail a = [1,2,3,4,5] assert_equal( [2,3,4,5], a.tail ) end def test_foot a = [1,2,3,4,5] assert_equal( [5], a.foot ) end def test_body a = [1,2,3,4,5] assert_equal( [1,2,3,4], a.body ) end end =end
Version data entries
25 entries across 25 versions & 1 rubygems