Class: KXI::Collections::HashCollection::HashEnumerator
- Inherits:
-
Enumerator
- Object
- Enumerator
- KXI::Collections::HashCollection::HashEnumerator
- Defined in:
- lib/kxi/collections/hash_collection.rb
Overview
Enumerates hash as key-value pairs represented by the KeyValuePair class
Defined Under Namespace
Classes: KeyValuePair
Instance Method Summary collapse
-
#current ⇒ Object
Returns current item.
-
#initialize(hash) ⇒ HashEnumerator
constructor
Instantiates the HashEnumerator class.
-
#next ⇒ Bool
Advances enumerator to next item.
-
#rewind ⇒ Bool
Selects first item in collection.
Constructor Details
#initialize(hash) ⇒ HashEnumerator
Instantiates the KXI::Collections::HashCollection::HashEnumerator class
45 46 47 48 49 |
# File 'lib/kxi/collections/hash_collection.rb', line 45 def initialize(hash) @hash = hash @keys = hash.keys @current = 0 end |
Instance Method Details
#current ⇒ Object
Returns current item
69 70 71 72 |
# File 'lib/kxi/collections/hash_collection.rb', line 69 def current k = @keys[@current] KeyValuePair.new(k, @hash[k]) end |
#next ⇒ Bool
Advances enumerator to next item
61 62 63 64 |
# File 'lib/kxi/collections/hash_collection.rb', line 61 def next @current += 1 return @keys.length > @current end |
#rewind ⇒ Bool
Selects first item in collection
53 54 55 56 |
# File 'lib/kxi/collections/hash_collection.rb', line 53 def rewind @current = 0 return @keys.length > 0 end |