Class: GoobyCounterHash
- Inherits:
-
Object
- Object
- GoobyCounterHash
- 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
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #decrement(key) ⇒ Object
- #increment(key) ⇒ Object
-
#initialize ⇒ GoobyCounterHash
constructor
A new instance of GoobyCounterHash.
- #sorted_keys ⇒ Object
- #value(key) ⇒ Object
Constructor Details
#initialize ⇒ GoobyCounterHash
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
#hash ⇒ Object (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_keys ⇒ Object
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 |