add card and deck model

This commit is contained in:
Jesse C. Fisher 2015-01-03 22:30:18 -08:00
parent febb3f6ac7
commit 6188096e61
2 changed files with 26 additions and 0 deletions

12
app/models/card.rb Normal file
View File

@ -0,0 +1,12 @@
class Card
RANKS = %w(3 4 5 6 7 8 9 10 J Q K A 2)
SUITS = %w(Spade Club Diamond Heart)
attr_accessor :value, :rank, :suit
def initialize(value, rank, suit)
self.value = value
self.rank = rank
self.suit = suit
end
end

14
app/models/deck.rb Normal file
View File

@ -0,0 +1,14 @@
class Deck
attr_accessor :cards
def initialize
# init each Card ordered by value
value = 1
self.cards = []
Card::RANKS.each do |rank|
Card::SUITS.each do |suit|
self.cards << Card.new(value, rank.to_i, suit)
value += 1
end
end
end
end