def group_items(items, opts = {})
      default_opts          = {:group_size => 10, :header => proc { |c| c.to_s[0, 1].upcase }}
      opts                  = default_opts.merge(opts)
      group_size            = opts[:group_size]
      header                = opts[:header]

      items                 = items.sort_by &header
      items_group_by_header = items.group_by &header

      items_by_headers      = []
      merge_headers         = []
      merge_items           = []

      items_group_by_header.sort.each do |header, items|
        merge_headers << header
        merge_items.concat items
        if merge_items.length >= group_size
          items_by_headers << [merge_headers, merge_items]
          merge_headers = []
          merge_items   = []
        end
      end

      if merge_items.length > 0
        items_by_headers << [merge_headers, merge_items]
      end
      items_by_headers
    end
def group_items(items, opts = {})
      default_opts          = {:group_size => 10, :header => proc { |c| c.to_s[0, 1].upcase }}
      opts                  = default_opts.merge(opts)
      group_size            = opts[:group_size]
      header                = opts[:header]

      items                 = items.sort_by &header
      items_group_by_header = items.group_by &header

      items_by_headers      = []
      merge_headers         = []
      merge_items           = []

      items_group_by_header.sort.each do |header, items|
        merge_headers << header
        merge_items.concat items
        if merge_items.length >= group_size
          items_by_headers << [merge_headers, merge_items]
          merge_headers = []
          merge_items   = []
        end
      end

      if merge_items.length > 0
        items_by_headers << [merge_headers, merge_items]
      end
      items_by_headers
    end
Groups array of objects.
 Ex.:
 ar = %{ aaa abc bbb bab }