Class: Array

Inherits:
Object show all
Defined in:
lib/arachni/ruby/array.rb

Overview

Arachni

Copyright (c) 2010-2012 Tasos "Zapotek" Laskos <[email protected]>

This is free software; you can copy and distribute and modify
this program under the term of the GPL v2.0 License
(See LICENSE file for details)

Instance Method Summary collapse

Instance Method Details

#chunk(pieces = 2) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/arachni/ruby/array.rb', line 13

def chunk( pieces = 2 )
    return self if pieces <= 0

    len    = self.length;
    mid    = ( len / pieces )
    chunks = []
    start  = 0

    1.upto( pieces ) do |i|
        last = start + mid
        last = last - 1 unless len % pieces >= i
        chunks << self[ start..last ] || []
        start = last + 1
    end

    return chunks
end