Class: Card

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

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

#rankObject



18
19
20
# File 'lib/blackjack/card.rb', line 18

def rank
  @rank
end

#suitObject



14
15
16
# File 'lib/blackjack/card.rb', line 14

def suit
  @suit
end

#to_sObject



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

#viewObject



33
34
35
36
# File 'lib/blackjack/card.rb', line 33

def view()
  view = VIEW[@rank]
  view ||= @rank
end