Module: Deals
- Extended by:
- T::Helpers, T::Sig
- Included in:
- Packet
- Defined in:
- lib/deck_of_cards_handler/packet/deals.rb
Overview
Includes dealing methods, that either returns a single Card or Packet(s) of cards
Instance Method Summary collapse
- #bottom_deal ⇒ Object
- #deal_into_piles(number_of_piles:, number_of_cards:) ⇒ Object
- #second_deal ⇒ Object
- #top_deal ⇒ Object
Instance Method Details
#bottom_deal ⇒ Object
25 26 27 28 29 |
# File 'lib/deck_of_cards_handler/packet/deals.rb', line 25 def bottom_deal raise StandardError if size.zero? T.must(cards.pop) end |
#deal_into_piles(number_of_piles:, number_of_cards:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/deck_of_cards_handler/packet/deals.rb', line 32 def deal_into_piles(number_of_piles:, number_of_cards:) raise StandardError, "Not enough cards" if (number_of_cards * number_of_piles) > size raise StandardError, "Invalid number_of_cards" unless number_of_cards.positive? piles = Array.new(number_of_piles) { [] } number_of_cards.times do piles.each { |pile| pile << top_deal } end piles.map { Packet.new(cards: _1) } end |
#second_deal ⇒ Object
18 19 20 21 22 |
# File 'lib/deck_of_cards_handler/packet/deals.rb', line 18 def second_deal raise StandardError if size < 2 T.must(cards.slice!(1)) end |
#top_deal ⇒ Object
11 12 13 14 15 |
# File 'lib/deck_of_cards_handler/packet/deals.rb', line 11 def top_deal raise StandardError if size.zero? T.must(cards.slice!(0)) end |