lib/cards_lib/deck.rb in cards_lib-0.2.4 vs lib/cards_lib/deck.rb in cards_lib-0.2.5
- old
+ new
@@ -1,12 +1,16 @@
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 }
+ @seed = options.fetch(:seed) { Random.new.seed }
@top = 0
- @cards = cards.map {|c| Card.new(c, ranker) }.shuffle(random: Random.new(@seed)).to_enum
+ @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