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

Version Path
ifttt-gdash-0.0.8 lib/gdash/monkey_patches.rb
ifttt-gdash-0.0.7 lib/gdash/monkey_patches.rb
ifttt-gdash-0.0.4 lib/gdash/monkey_patches.rb
ifttt-gdash-0.0.3 lib/gdash/monkey_patches.rb
ifttt-gdash-0.0.2b lib/gdash/monkey_patches.rb
gdash-0.0.5 lib/gdash/monkey_patches.rb
gdash-0.0.4 lib/gdash/monkey_patches.rb
gdash-0.0.3 lib/gdash/monkey_patches.rb
ifttt-gdash-0.0.2a lib/gdash/monkey_patches.rb
gdash-0.0.2 lib/gdash/monkey_patches.rb
gdash-0.0.1 lib/gdash/monkey_patches.rb