Sha256: 3471fa3da36e23de365e30af4bcfa0521235a658bd6641b980410fe90ffe96a6

Contents?: true

Size: 468 Bytes

Versions: 18

Compression:

Stored size: 468 Bytes

Contents

unless Enumerable.method_defined? :frequencies
  module Enumerable
    # Counts the number of occurrence of items in the enumerable.
    #
    # @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

18 entries across 15 versions & 5 rubygems

Version Path
powerpack-0.1.3 lib/powerpack/enumerable/frequencies.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/enumerable/frequencies.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/enumerable/frequencies.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/enumerable/frequencies.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/powerpack-0.1.2/lib/powerpack/enumerable/frequencies.rb
powerpack-0.1.2 lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/enumerable/frequencies.rb
powerpack-0.1.1 lib/powerpack/enumerable/frequencies.rb