Module: HandIteration
- Included in:
- Hand
- Defined in:
- tomes/components/deck_builder/hand_iteration.rb
Overview
Provides some methods for iterating over a hand.
Instance Method Summary collapse
-
#each ⇒ Void
(also: #each_with_index)
Iterates through #cards and calls the block on each Card.
-
#index(search_card, &block) ⇒ Array<Integers>
Calls ‘#index` on #cards.
-
#map(&block) ⇒ Array
Calls #map on #cards.
-
#select ⇒ Array<Cards>
Returns an array of cards for which the block returns a truthy value.
Instance Method Details
#each ⇒ Void Also known as: each_with_index
Iterates through #cards and calls the block on each Card.
7 8 9 10 11 12 13 14 15 |
# File 'tomes/components/deck_builder/hand_iteration.rb', line 7 def each index = 0 iteration_limit = cards.length until index >= iteration_limit yield cards[index], index index += 1 end end |
#index(search_card, &block) ⇒ Array<Integers>
Calls ‘#index` on #cards.
38 39 40 |
# File 'tomes/components/deck_builder/hand_iteration.rb', line 38 def index(search_card, &block) cards.index(search_card, &block) end |
#map(&block) ⇒ Array
Calls #map on #cards.
20 21 22 |
# File 'tomes/components/deck_builder/hand_iteration.rb', line 20 def map(&block) cards.map(&block) end |
#select ⇒ Array<Cards>
Returns an array of cards for which the block returns a truthy value.
26 27 28 29 30 31 32 33 34 |
# File 'tomes/components/deck_builder/hand_iteration.rb', line 26 def select selection = [] each do |card| selection << card if yield card end selection end |