module PlayingCards::Deck
functional representation of a deck of cards
Public Instance Methods
build(shoe_size=1)
click to toggle source
# File lib/playing_cards/deck.rb, line 10 def build(shoe_size=1) build_deck*shoe_size end
cut(cards)
click to toggle source
# File lib/playing_cards/deck.rb, line 19 def cut(cards) top, bottom = cut_into_2_piles(cards) bottom + top # flop that shit end
deal(cards)
click to toggle source
# File lib/playing_cards/deck.rb, line 24 def deal(cards) dealt = cards.first [dealt, cards - [dealt]] end
shuffle(cards)
click to toggle source
# File lib/playing_cards/deck.rb, line 14 def shuffle(cards) copy = cards.dup copy.sort_by { rand } end
Private Instance Methods
build_deck()
click to toggle source
# File lib/playing_cards/deck.rb, line 36 def build_deck Card::RANKS.flat_map {|rank| Card::SUITS.flat_map {|suit| Card.new(rank, suit) } } end
cut_into_2_piles(cards)
click to toggle source
# File lib/playing_cards/deck.rb, line 31 def cut_into_2_piles(cards) cut_at = rand(4..cards.length-4) # never cut closer than 4 form the top or bottom [cards[0..cut_at-1], cards[cut_at, cards.length-cut_at]] end