Class: Ambry::KeyIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ambry/abstract_key_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#callableObject (readonly)

Returns the value of attribute callable


101
102
103
# File 'lib/ambry/abstract_key_set.rb', line 101

def callable
  @callable
end

#keysObject (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

#lastObject


112
113
114
# File 'lib/ambry/abstract_key_set.rb', line 112

def last
  callable.call keys.last
end

#reverseObject


108
109
110
# File 'lib/ambry/abstract_key_set.rb', line 108

def reverse
  KeyIterator.new(keys.reverse, &callable)
end