Class: GoobyCounterHash

Inherits:
Object
  • Object
show all
Defined in:
lib/gooby_counter_hash.rb

Overview

Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGoobyCounterHash

Returns a new instance of GoobyCounterHash.



12
13
14
# File 'lib/gooby_counter_hash.rb', line 12

def initialize
  @hash = Hash.new(0)
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



10
11
12
# File 'lib/gooby_counter_hash.rb', line 10

def hash
  @hash
end

Instance Method Details

#decrement(key) ⇒ Object



22
23
24
25
26
# File 'lib/gooby_counter_hash.rb', line 22

def decrement(key)
  new_value  = @hash[key] - 1
  @hash[key] = new_value
  new_value
end

#increment(key) ⇒ Object



16
17
18
19
20
# File 'lib/gooby_counter_hash.rb', line 16

def increment(key)
  new_value  = @hash[key] + 1
  @hash[key] = new_value
  new_value
end

#sorted_keysObject



32
33
34
# File 'lib/gooby_counter_hash.rb', line 32

def sorted_keys
  @hash.keys.sort
end

#value(key) ⇒ Object



28
29
30
# File 'lib/gooby_counter_hash.rb', line 28

def value(key)
  @hash[key]
end