Sha256: 5ae7cf62e41df5eb246957e8b93ab4d6817fd7d2a1ce9d2a5661c83e6584b1d0

Contents?: true

Size: 721 Bytes

Versions: 1

Compression:

Stored size: 721 Bytes

Contents

require 'forwardable'

module Podos
  class Deck
    extend Forwardable

    def_delegators :@cards, :count, :<<, :map, :shuffle!

    attr_accessor :cards

    def initialize cards = []
      # Todo raise if duplicate

      @cards = cards
    end

    def self.from_str str
      self.new str.split(' ').map { |str| Card.from_str str }
    end

    def deal number
      @cards.shift number
    end

    # def remove_card(card)
    #   cards = @cards.select { |c| c != card }
    # end

    def to_s
      @cards.map(&:to_s).join ' '
    end

    def + other_deck
      self.new @cards + other_deck.cards
    end

    def - other_deck
      self.new @cards.select { |c| !other_deck.cards.include? c }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
podos-0.1.1 lib/podos/deck.rb