Sha256: bd8940cfdb6396e9ee71864f4ba0c77da1b9c1e35c25ce8fa0f10def0e774a9a

Contents?: true

Size: 346 Bytes

Versions: 2

Compression:

Stored size: 346 Bytes

Contents

# frozen_string_literal: true

require 'huffman_coding/utils'

class << HuffmanCoding::Utils
  if Enumerable.method_defined?(:tally)
    def tally(enumerable)
      enumerable.tally
    end
  else
    def tally(enumerable)
      hash = Hash.new(0)
      enumerable.each{|key| hash[key] += 1 }
      return hash
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
huffman_coding-1.1.0 lib/huffman_coding/utils/tally.rb
huffman_coding-1.0.0 lib/huffman_coding/utils/tally.rb