Sha256: 86ba7318a81fed4b52c24d3dfdaacc3fe40423477e92f9bd9991a7ae731225ca
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
module CardsLib class Deck def initialize(options = {}) cards = options.fetch(:cards) { Standard::PLAYING_CARDS } ranker = options.fetch(:ranker){ Ranker } @seed = options.fetch(:seed) { Random.new.seed } @top = 0 @cards = if cards.all? {|c| c.is_a? Card } cards else cards.map {|c| Card.new(c, ranker) } end.shuffle(random: Random.new(@seed)).to_enum end def inspect "<Deck: #{size} Cards - Seed##{@seed}>" end def cards @cards end def peak Array(_cards[@top..@top]).first end def pluck card = peak @top += 1 unless @top == _cards.size card || card.tap {|i| i.define_singleton_method(:face) { nil } } end def return_card @top -= 1 unless @top == 0 end def empty? !peak end def present? !empty? end def size _cards[@top..-1].size end def count size end def face_up @cards.map(&:face) end private def _cards @cards.to_a end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.2.5 | lib/cards_lib/deck.rb |