Class: Lafcadio::HashOfArrays
- Inherits:
-
Object
- Object
- Lafcadio::HashOfArrays
- Defined in:
- lib/lafcadio/util/HashOfArrays.rb
Overview
:nodoc:
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, array) ⇒ Object
- #each ⇒ Object
- #get(key) ⇒ Object
- #getArray(key) ⇒ Object
-
#initialize ⇒ HashOfArrays
constructor
A new instance of HashOfArrays.
- #keys ⇒ Object
- #set(key, array) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ HashOfArrays
Returns a new instance of HashOfArrays.
3 4 5 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 3 def initialize @values = {} end |
Instance Method Details
#[](key) ⇒ Object
30 31 32 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 30 def [](key) getArray key end |
#[]=(key, array) ⇒ Object
12 13 14 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 12 def []=(key, array) set key, array end |
#each ⇒ Object
44 45 46 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 44 def each @values.each { |key, array| yield key, array } end |
#get(key) ⇒ Object
25 26 27 28 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 25 def get(key) array = @values[key] array != nil ? array[0] : nil end |
#getArray(key) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 16 def getArray(key) array = @values[key] if array == nil array = [] @values[key] = array end array end |
#keys ⇒ Object
40 41 42 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 40 def keys @values.keys end |
#set(key, array) ⇒ Object
7 8 9 10 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 7 def set(key, array) raise "HashOfArrays.[]= needs a value of type Array" if array.class != Array @values[key] = array end |
#values ⇒ Object
34 35 36 37 38 |
# File 'lib/lafcadio/util/HashOfArrays.rb', line 34 def values values = [] @values.values.each { |val| values << val[0] } values end |