Class: Ambry::KeyIterator
- Inherits:
-
Object
- Object
- Ambry::KeyIterator
- Includes:
- Enumerable
- Defined in:
- lib/ambry/abstract_key_set.rb
Instance Attribute Summary collapse
-
#callable ⇒ Object
readonly
Returns the value of attribute callable.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(keys, &callable) ⇒ KeyIterator
constructor
A new instance of KeyIterator.
- #last ⇒ Object
- #reverse ⇒ Object
Constructor Details
#initialize(keys, &callable) ⇒ KeyIterator
Returns a new instance of KeyIterator.
103 104 105 106 |
# File 'lib/ambry/abstract_key_set.rb', line 103 def initialize(keys, &callable) @keys = keys @callable = callable end |
Instance Attribute Details
#callable ⇒ Object (readonly)
Returns the value of attribute callable.
101 102 103 |
# File 'lib/ambry/abstract_key_set.rb', line 101 def callable @callable end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
101 102 103 |
# File 'lib/ambry/abstract_key_set.rb', line 101 def keys @keys end |
Instance Method Details
#each(&block) ⇒ Object
116 117 118 |
# File 'lib/ambry/abstract_key_set.rb', line 116 def each(&block) block_given? ? keys.each {|k| yield callable.call(k)} : to_enum end |
#last ⇒ Object
112 113 114 |
# File 'lib/ambry/abstract_key_set.rb', line 112 def last callable.call keys.last end |
#reverse ⇒ Object
108 109 110 |
# File 'lib/ambry/abstract_key_set.rb', line 108 def reverse KeyIterator.new(keys.reverse, &callable) end |