### Home Classes Methods

### In Files

- lib/mcollective/monkey_patches.rb

### Parent

Object

### Methods

- #in_groups_of

### Files

- COPYING
- README
- Rakefile
- PLACEHOLDER
- PLACEHOLDER

### Class/Module Index

Quicksearch

- MCollective
- MCollective::Agent
- MCollective::Agents
- MCollective::Aggregate
- MCollective::Aggregate::Base
- MCollective::Aggregate::Result
- MCollective::Aggregate::Result::Base
- MCollective::Aggregate::Result::CollectionResult
- MCollective::Aggregate::Result::NumericResult
- MCollective::Application
- MCollective::Applications
- MCollective::Client
- MCollective::Config
- MCollective::Connector
- MCollective::Connector::Base
- MCollective::DDL
- MCollective::DDLValidationError
- MCollective::Data
- MCollective::Data::Base
- MCollective::Data::Result
- MCollective::Discovery
- MCollective::Facts
- MCollective::Facts::Base
- MCollective::Generators
- MCollective::Generators::AgentGenerator
- MCollective::Generators::Base
- MCollective::Generators::DataGenerator
- MCollective::InvalidRPCData
- MCollective::Log
- MCollective::Logger
- MCollective::Logger::Base
- MCollective::Logger::Console_logger
- MCollective::Logger::File_logger
- MCollective::Logger::Syslog_logger
- MCollective::Matcher
- MCollective::Matcher::Parser
- MCollective::Matcher::Scanner
- MCollective::Message
- MCollective::MissingRPCData
- MCollective::MsgDoesNotMatchRequestID
- MCollective::MsgTTLExpired
- MCollective::NotTargettedAtUs
- MCollective::Optionparser
- MCollective::PluginManager
- MCollective::PluginPackager
- MCollective::PluginPackager::AgentDefinition
- MCollective::PluginPackager::StandardDefinition
- MCollective::RPC
- MCollective::RPC::ActionRunner
- MCollective::RPC::Agent
- MCollective::RPC::Audit
- MCollective::RPC::Client
- MCollective::RPC::Helpers
- MCollective::RPC::Progress
- MCollective::RPC::Reply
- MCollective::RPC::Request
- MCollective::RPC::Result
- MCollective::RPC::Stats
- MCollective::RPCAborted
- MCollective::RPCError
- MCollective::Registration
- MCollective::Registration::Base
- MCollective::Runner
- MCollective::RunnerStats
- MCollective::SSL
- MCollective::Security
- MCollective::Security::Base
- MCollective::SecurityValidationFailed
- MCollective::Shell
- MCollective::UnixDaemon
- MCollective::UnknownRPCAction
- MCollective::UnknownRPCError
- MCollective::Util
- MCollective::WindowsDaemon
- Array
- Dir
- Object
- String
- Symbol

No matching classes.

# Array

a method # that walks an array in groups, pass a block to call the block on each sub array

### Public Instance Methods

in_groups_of(chunk_size, padded_with=nil, &block) click to toggle source

    # File lib/mcollective/monkey_patches.rb, line 29
    def in_groups_of(chunk_size, padded_with=nil, &block)
      arr = self.clone

      # how many to add
      padding = chunk_size - (arr.size % chunk_size)

      # pad at the end
      arr.concat([padded_with] * padding) unless padding == chunk_size

      # 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_with_index do |a, i|
          case block.arity
            when 1
              yield(a)
            when 2
              yield(a, (i == result.size - 1))
            else
              raise "Expected 1 or 2 arguments, got #{block.arity}"
          end
        end
      else
        result
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.