add card and deck model
This commit is contained in:
parent
febb3f6ac7
commit
6188096e61
12
app/models/card.rb
Normal file
12
app/models/card.rb
Normal 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
14
app/models/deck.rb
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user