Class HashBag
In: lib/hash_bag.rb
Parent: Hash

Hash that keeps a count for each key

Methods

[]=   count   new  

Public Class methods

[Source]

   # File lib/hash_bag.rb, line 4
4:   def initialize
5:     @counts = {}
6:     super
7:   end

Public Instance methods

[Source]

    # File lib/hash_bag.rb, line 9
 9:   def []=(key, value)
10:     count = count(key)
11:     count = count + 1
12:     @counts[key] = count
13:     super
14:   end

[Source]

    # File lib/hash_bag.rb, line 16
16:   def count(key)
17:     count = @counts[key]
18: 
19:     if count != nil
20:       count    
21:     else
22:       0
23:     end
24:   end

[Validate]