class HashBag

Hash that keeps a count for each key

Public Class Methods

new() click to toggle source
# File lib/hash_bag.rb, line 4
def initialize
  @counts = {}
  super
end

Public Instance Methods

[]=(key, value) click to toggle source
# File lib/hash_bag.rb, line 9
def []=(key, value)
  count = count(key)
  count = count + 1
  @counts[key] = count
  super
end
count(key) click to toggle source
# File lib/hash_bag.rb, line 16
def count(key)
  count = @counts[key]

  if count != nil
    count    
  else
    0
  end
end