Class: Blackjack::Card
- Inherits:
-
Object
- Object
- Blackjack::Card
- Defined in:
- lib/blackjack/card.rb
Instance Attribute Summary collapse
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(rank, suit) ⇒ Card
constructor
A new instance of Card.
- #is_ace? ⇒ Boolean
- #is_facecard? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(rank, suit) ⇒ Card
Returns a new instance of Card.
4 5 6 7 |
# File 'lib/blackjack/card.rb', line 4 def initialize(rank, suit) @rank = rank @suit = suit end |
Instance Attribute Details
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
3 4 5 |
# File 'lib/blackjack/card.rb', line 3 def rank @rank end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
3 4 5 |
# File 'lib/blackjack/card.rb', line 3 def suit @suit end |
Instance Method Details
#display ⇒ Object
9 10 11 |
# File 'lib/blackjack/card.rb', line 9 def display rank.to_s + suit end |
#is_ace? ⇒ Boolean
13 14 15 |
# File 'lib/blackjack/card.rb', line 13 def is_ace? rank == 'A' end |
#is_facecard? ⇒ Boolean
17 18 19 |
# File 'lib/blackjack/card.rb', line 17 def is_facecard? 'JQK'.include?(rank.to_s) end |
#value ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blackjack/card.rb', line 21 def value case when is_facecard? 10 when is_ace? 1 else rank end end |