Class: Card

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#faceupObject

Returns the value of attribute faceup.



298
299
300
# File 'lib/cardtable.rb', line 298

def faceup
  @faceup
end

#imageObject

Returns the value of attribute image.



298
299
300
# File 'lib/cardtable.rb', line 298

def image
  @image
end

#rankObject

Returns the value of attribute rank.



298
299
300
# File 'lib/cardtable.rb', line 298

def rank
  @rank
end

#scoreObject

Returns the value of attribute score.



298
299
300
# File 'lib/cardtable.rb', line 298

def score
  @score
end

#suitObject

Returns the value of attribute suit.



298
299
300
# File 'lib/cardtable.rb', line 298

def suit
  @suit
end