Sha256: 2b00e0379dd736c0b88ca09ac2201571eb5d0c7f16e87a9063aaf3b6748f81a5
Contents?: true
Size: 888 Bytes
Versions: 10
Compression:
Stored size: 888 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 _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
10 entries across 10 versions & 1 rubygems