Class: HornOfPlenty::Collection
- Inherits:
-
Object
- Object
- HornOfPlenty::Collection
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/horn_of_plenty/collection.rb
Instance Method Summary
collapse
Constructor Details
#initialize(items:, parser:) ⇒ Collection
Returns a new instance of Collection.
15
16
17
18
|
# File 'lib/horn_of_plenty/collection.rb', line 15
def initialize(items:, parser:)
self.raw_items = items
self.parser = parser
end
|
Instance Method Details
#[](index) ⇒ Object
20
21
22
|
# File 'lib/horn_of_plenty/collection.rb', line 20
def [](index)
items[index] ||= transform(raw_items[index])
end
|
#each ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/horn_of_plenty/collection.rb', line 38
def each
raw_items.each_with_index do |raw_item, index|
items[index] = items[index] || transform(raw_item)
yield items[index]
end
end
|
#first ⇒ Object
24
25
26
|
# File 'lib/horn_of_plenty/collection.rb', line 24
def first
items[0] ||= transform(raw_items[0])
end
|
#pop(*args) ⇒ Object
33
34
35
36
|
# File 'lib/horn_of_plenty/collection.rb', line 33
def pop(*args)
raw_items.pop(*args)
items.pop(*args)
end
|
#shift(*args) ⇒ Object
28
29
30
31
|
# File 'lib/horn_of_plenty/collection.rb', line 28
def shift(*args)
raw_items.shift(*args)
items.shift(*args)
end
|