Sha256: 94769b1725ccaa8682913701526b068ace05459ae2a174cc16d31385c65c8e41
Contents?: true
Size: 950 Bytes
Versions: 1
Compression:
Stored size: 950 Bytes
Contents
module CardsLib class Deck def initialize(options = {}) cards = options.fetch(:cards) { Standard::PLAYING_CARDS } @seed = options.fetch(:seed) { Random.new.seed } @top = 0 @cards = cards.map {|c| Card.new(c) }.shuffle(random: Random.new(@seed)).to_enum 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 if @top <= _cards.size _cards[@top..-1].size else 0 end 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.0.3 | lib/cards_lib/deck.rb |