Class: Card
- Inherits:
-
Object
- Object
- Card
- Defined in:
- lib/cardtable.rb
Constant Summary collapse
- RANKS =
%w(2 3 4 5 6 7 8 9 10 J Q K A)
- SCORES =
%w(2 3 4 5 6 7 8 9 10 10 10 10 11)
- SUITS =
%w(Spades Clubs Hearts Diamonds)
Instance Attribute Summary collapse
-
#faceup ⇒ Object
Returns the value of attribute faceup.
-
#image ⇒ Object
Returns the value of attribute image.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#score ⇒ Object
Returns the value of attribute score.
-
#suit ⇒ Object
Returns the value of attribute suit.
Instance Method Summary collapse
-
#initialize(index) ⇒ Card
constructor
A new instance of Card.
Constructor Details
#initialize(index) ⇒ Card
Returns a new instance of Card.
300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/cardtable.rb', line 300 def initialize(index) # Init the rank, suit, score and image of each card based on the # argument passed in self.rank = RANKS[index % 13] self.score = SCORES[index % 13] self.suit = SUITS[index % 4] self.image = "/images/" + self.rank + self.suit + ".png" # By default, each card is assumed to be dealt face up. When we start # playing, only the second card of the dealer will be dealt face down. # When it is the dealer's turn to play, this card will be set to be face up self.faceup = true end |
Instance Attribute Details
#faceup ⇒ Object
Returns the value of attribute faceup.
298 299 300 |
# File 'lib/cardtable.rb', line 298 def faceup @faceup end |
#image ⇒ Object
Returns the value of attribute image.
298 299 300 |
# File 'lib/cardtable.rb', line 298 def image @image end |
#rank ⇒ Object
Returns the value of attribute rank.
298 299 300 |
# File 'lib/cardtable.rb', line 298 def rank @rank end |
#score ⇒ Object
Returns the value of attribute score.
298 299 300 |
# File 'lib/cardtable.rb', line 298 def score @score end |
#suit ⇒ Object
Returns the value of attribute suit.
298 299 300 |
# File 'lib/cardtable.rb', line 298 def suit @suit end |