Created
November 21, 2015 19:04
-
-
Save framallo/5e11ed9808e1af8a3c61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Deck | |
attr_accessor :cards | |
def initialize | |
build_every_possible_card | |
end | |
def build | |
self.cards = | |
suits.map do |suit| | |
ranks.map do |rank| | |
colors.map do |color| | |
Card.new(suit, rank, color) | |
end | |
end | |
end.flatten | |
end | |
def shuffle | |
@cards.shuffle! | |
end | |
def deal | |
@cards.shift | |
end | |
def suits | |
raise 'you need to override this method' | |
end | |
def ranks | |
raise 'you need to override this method' | |
end | |
def colors | |
raise 'you need to override this method' | |
end | |
class Card | |
attr_accessor :suit, :rank, :color | |
def initialize(suit, rank, color) | |
@suit = suit | |
@rank = rank | |
@color = color | |
end | |
end | |
end | |
class FrenchDeck < Deck | |
def suits | |
['clubs', 'hearts', 'spades'] | |
end | |
def ranks | |
['ace', 2, 3, 4, 5 ,6 ,7 ,8 ,9 ,10, 'jack', 'queen', 'king'] | |
end | |
def colors | |
['black', 'red'] | |
end | |
end | |
class ItalianDeck < Deck | |
def suits | |
end | |
def ranks | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment