Sha256: 0599b4361406f068f269f3ea087b9dad4df57e407e59d405a0e3b762fc4ea07c

Contents?: true

Size: 468 Bytes

Versions: 6

Compression:

Stored size: 468 Bytes

Contents

unless Enumerable.method_defined? :frequencies
  module Enumerable
    # Counts the number of ocurrence of items in the enumberable.
    #
    # @return [Hash] in the format value => count
    #
    # @example
    #   [].frequencies # => {}
    #   [1, :symbol, 'string', 3, :symbol, 1].frequencies
    #     #=> { 1 => 2, :symbol => 2, 'string' => 1, 3 => 1 }
    #
    #
    def frequencies
      each_with_object(Hash.new(0)) { |e, a| a[e] += 1 }
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/lib/powerpack/enumerable/frequencies.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/lib/powerpack/enumerable/frequencies.rb
powerpack-0.1.0 lib/powerpack/enumerable/frequencies.rb
powerpack-0.0.9 lib/powerpack/enumerable/frequencies.rb
powerpack-0.0.8 lib/powerpack/enumerable/frequencies.rb
powerpack-0.0.7 lib/powerpack/enumerable/frequencies.rb