Class: Deck
Overview
A Hand that uses and generates other Hands
Constant Summary collapse
- VALID_REFERENCES =
[Integer, Range, Symbol].freeze
Instance Attribute Summary
Attributes inherited from Hand
Instance Method Summary collapse
-
#[](*references) ⇒ Array
Returns both Cards via their indices in #cards and Hands via their key in #hands.
-
#deal(number_of_cards = 1) ⇒ Card, Array
Removes and returns the topmost card in the draw stack.
-
#deal_to(*hands, number_of_cards: 1) ⇒ Object
Deals cards to the provided hands.
-
#generate_hands(number_of_hands, number_of_cards = 5) ⇒ Object
Deals the provided number of cards to the provided number of hands.
Methods inherited from Hand
#all_types, #all_values, #discard, #discard_index, #move, #pop, #receive, #shuffle!, #sort!
Methods included from HandInformation
#empty?, #full?, #include?, #length
Methods included from HandIteration
Instance Method Details
#[](*references) ⇒ Array
Returns both Cards via their indices in #cards and Hands via their key in #hands.
Both can be referenced in a single call.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'tomes/components/deck_builder/deck.rb', line 32 def [](*references) results = sort_references(references).map do |reference| if reference.is_a?(Integer) || reference.is_a?(Range) cards[reference] elsif reference.is_a? Symbol hands[reference] end end results.flatten end |
#deal(number_of_cards = 1) ⇒ Card, Array
Removes and returns the topmost card in the draw stack.
54 55 56 |
# File 'tomes/components/deck_builder/deck.rb', line 54 def deal(number_of_cards = 1) hands[:draw].pop(number_of_cards) end |
#deal_to(*hands, number_of_cards: 1) ⇒ Object
Deals cards to the provided hands.
61 62 63 |
# File 'tomes/components/deck_builder/deck.rb', line 61 def deal_to(*hands, number_of_cards: 1) hands.each { |hand| hand.draw(deal(number_of_cards)) } end |
#generate_hands(number_of_hands, number_of_cards = 5) ⇒ Object
Deals the provided number of cards to the provided number of hands.
47 48 49 |
# File 'tomes/components/deck_builder/deck.rb', line 47 def generate_hands(number_of_hands, number_of_cards = 5) Array.new(number_of_hands) { Hand.new(deal(number_of_cards)) } end |