def extract(map)
    # clone map hash, swap keys for string
    map = Hash[map]
    map.keys.each { |k|
      map[k.to_s] = map[k]
      map.delete(k) unless k.is_a?(String)
    }

    groups = []
    i = 0
    while(i < length) do
      val = self[i]
      i += 1
      next unless !!map.has_key?(val)

      num = map[val]
      group = [val]
      0.upto(num-1) do |j|
        group << self[i]
        i += 1
      end
      groups << group
    end

    groups
  end
def extract(map)
    # clone map hash, swap keys for string
    map = Hash[map]
    map.keys.each { |k|
      map[k.to_s] = map[k]
      map.delete(k) unless k.is_a?(String)
    }

    groups = []
    i = 0
    while(i < length) do
      val = self[i]
      i += 1
      next unless !!map.has_key?(val)

      num = map[val]
      group = [val]
      0.upto(num-1) do |j|
        group << self[i]
        i += 1
      end
      groups << group
    end

    groups
  end
Extract groups of values from argument list

 Groups are generated by comparing arguments to keys in the
 specified map and on matches extracting the # of following
 arguments specified by the map values

 Note arguments / keys are converted to strings before comparison

 @example
   args = Arguments.new :args => ['with_id', 123, 'custom', 'another']
   args.extract :with_id => 1, :custom => 0
     # => [['with_id', 123], ['custom']]