class RubyPlayingCards::Dealer

Public Class Methods

cut!(deck, index=26) click to toggle source
# File lib/ruby_playing_cards/dealer.rb, line 6
def cut!(deck, index=26)
  top = deck.cards.shift(index)
  deck.cards = deck.cards + top
end
deal(deck, hand_size: 1, player_count: 1) click to toggle source
# File lib/ruby_playing_cards/dealer.rb, line 11
def deal(deck, hand_size: 1, player_count: 1)
  hands = []
  card_total = hand_size * player_count

  player_count.times do |player_index|
    hand = build_hand(deck, player_index, card_total, player_count)
    hands << hand
  end 
  
  deck.cards.shift(card_total)
  hands
end
draw(deck, card_count=1) click to toggle source
# File lib/ruby_playing_cards/dealer.rb, line 24
def draw(deck, card_count=1)
  deck.cards.shift card_count
end
shuffle(deck) click to toggle source
# File lib/ruby_playing_cards/dealer.rb, line 28
def shuffle(deck)
  deck.cards.shuffle!
end

Private Class Methods

build_hand(deck, player_index, card_count, player_count) click to toggle source
# File lib/ruby_playing_cards/dealer.rb, line 33
def build_hand(deck, player_index, card_count, player_count)
  cards = []
  (player_index+1).step(card_count,player_count) { |deck_index| cards << deck.cards[deck_index-1]}
  Hand.new(cards, "player#{player_index+1}")
end