Class: Wads::HashOfHashes
- Inherits:
-
Object
- Object
- Wads::HashOfHashes
- Defined in:
- lib/wads/data_structures.rb
Overview
A convenience data structure to store multiple, named sets of key/value pairs
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#get(data_set_name, x) ⇒ Object
Retrieve the value for the given key x in the named data set.
-
#initialize ⇒ HashOfHashes
constructor
A new instance of HashOfHashes.
-
#keys(data_set_name) ⇒ Object
Get the list of keys for the named data set.
-
#set(data_set_name, x, y) ⇒ Object
Store the value y based on the key x for the named data set.
Constructor Details
#initialize ⇒ HashOfHashes
Returns a new instance of HashOfHashes.
34 35 36 |
# File 'lib/wads/data_structures.rb', line 34 def initialize @data = {} end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
32 33 34 |
# File 'lib/wads/data_structures.rb', line 32 def data @data end |
Instance Method Details
#get(data_set_name, x) ⇒ Object
Retrieve the value for the given key x in the named data set
53 54 55 56 57 58 59 |
# File 'lib/wads/data_structures.rb', line 53 def get(data_set_name, x) data_set = @data[data_set_name] if data_set.nil? return nil end data_set[x] end |
#keys(data_set_name) ⇒ Object
Get the list of keys for the named data set
64 65 66 67 68 69 70 |
# File 'lib/wads/data_structures.rb', line 64 def keys(data_set_name) data_set = @data[data_set_name] if data_set.nil? return nil end data_set.keys end |
#set(data_set_name, x, y) ⇒ Object
Store the value y based on the key x for the named data set
41 42 43 44 45 46 47 48 |
# File 'lib/wads/data_structures.rb', line 41 def set(data_set_name, x, y) data_set = @data[data_set_name] if data_set.nil? data_set = {} @data[data_set_name] = data_set end data_set[x] = y end |