Sha256: b55211b20731aa1141e3419ef83c55df181687024e5a1995ff7f040072f37538
Contents?: true
Size: 751 Bytes
Versions: 11
Compression:
Stored size: 751 Bytes
Contents
class Array def in_groups_of(chunk_size, padded_with=nil) if chunk_size <= 1 if block_given? self.each{|a| yield([a])} else self end else arr = self.clone # how many to add padding = chunk_size - (arr.size % chunk_size) padding = 0 if padding == chunk_size # pad at the end arr.concat([padded_with] * padding) # how many chunks we'll make count = arr.size / chunk_size # make that many arrays result = [] count.times {|s| result << arr[s * chunk_size, chunk_size]} if block_given? result.each{|a| yield(a)} else result end end end end class GraphiteGraph attr_accessor :properties, :file end
Version data entries
11 entries across 11 versions & 2 rubygems