Sha256: 31b6de9fdd1afd9e8ef6336ed3d459fd1b390d26711f206d8d4daf22c61842ac
Contents?: true
Size: 624 Bytes
Versions: 1
Compression:
Stored size: 624 Bytes
Contents
module CardsLib class Deck def initialize(cards = Standard::PLAYING_CARDS, options = {}) @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.to_a[@top..@top]).first end def pluck card = Array(@cards.to_a[@top..@top]).first @top += 1 unless @top == cards.to_a.size card || card.tap {|i| i.define_singleton_method(:face) { nil } } end def return_card @top -= 1 unless @top == 0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.0.1 | lib/cards_lib/deck.rb |