Skip to content

Instantly share code, notes, and snippets.

@framallo
Created November 21, 2015 19:04
Show Gist options
  • Save framallo/5e11ed9808e1af8a3c61 to your computer and use it in GitHub Desktop.
Save framallo/5e11ed9808e1af8a3c61 to your computer and use it in GitHub Desktop.
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