Class: Card
- Inherits:
-
Object
- Object
- Card
- Defined in:
- lib/blackjack/card.rb
Constant Summary collapse
- SUITS =
[:spade, :club, :heart, :diamond]
- ICONS =
{ spade:"\u2660", club:"\u2663", heart:"\u2665", diamond:"\u2666" }
- VIEW =
{ 1 => "A", 11 => "J", 12 => "Q", 13 => "K", 14 => "A" }
Instance Method Summary collapse
-
#initialize(suit, rank) ⇒ Card
constructor
A new instance of Card.
- #rank ⇒ Object
- #suit ⇒ Object
- #to_s ⇒ Object
- #value(ace = :high) ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize(suit, rank) ⇒ Card
Returns a new instance of Card.
8 9 10 11 12 |
# File 'lib/blackjack/card.rb', line 8 def initialize(suit, rank) @suit = suit @rank = rank @view = self.view() end |
Instance Method Details
#rank ⇒ Object
18 19 20 |
# File 'lib/blackjack/card.rb', line 18 def rank @rank end |
#suit ⇒ Object
14 15 16 |
# File 'lib/blackjack/card.rb', line 14 def suit @suit end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/blackjack/card.rb', line 38 def to_s() "#{ICONS[@suit]}#{@view}" end |
#value(ace = :high) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/blackjack/card.rb', line 22 def value(ace=:high) val = if @rank == 14 or @rank == 1 ace == :high ? 11 : 1 elsif @rank >= 11 and @rank <= 13 10 else @rank end end |
#view ⇒ Object
33 34 35 36 |
# File 'lib/blackjack/card.rb', line 33 def view() view = VIEW[@rank] view ||= @rank end |