Class: Card

Inherits:
Object
  • Object
show all
Defined in:
lib/blackjack/card.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blackjack, value, suit) ⇒ Card

Returns a new instance of Card.



6
7
8
9
10
# File 'lib/blackjack/card.rb', line 6

def initialize(blackjack, value, suit)
  @blackjack = blackjack
  @value = value
  @suit = suit
end

Instance Attribute Details

#blackjackObject (readonly)

Returns the value of attribute blackjack.



4
5
6
# File 'lib/blackjack/card.rb', line 4

def blackjack
  @blackjack
end

#suitObject (readonly)

Returns the value of attribute suit.



4
5
6
# File 'lib/blackjack/card.rb', line 4

def suit
  @suit
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/blackjack/card.rb', line 4

def value
  @value
end

Class Method Details

.facesObject



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

def self.faces
  [%w[🂡 🂱 🃁 🃑], %w[🂢 🂲 🃂 🃒], %w[🂣 🂳 🃃 🃓], %w[🂤 🂴 🃄 🃔],
   %w[🂥 🂵 🃅 🃕], %w[🂦 🂶 🃆 🃖], %w[🂧 🂷 🃇 🃗], %w[🂨 🂸 🃈 🃘],
   %w[🂩 🂹 🃉 🃙], %w[🂪 🂺 🃊 🃚], %w[🂫 🂻 🃋 🃛], %w[🂭 🂽 🃍 🃝],
   %w[🂮 🂾 🃎 🃞], %w[🂠]]
end

.faces2Object



39
40
41
42
43
44
45
46
47
# File 'lib/blackjack/card.rb', line 39

def self.faces2
  [%w[A♠ A♥ A♣ A♦], %w[2♠ 2♥ 2♣ 2♦],
   %w[3♠ 3♥ 3♣ 3♦], %w[4♠ 4♥ 4♣ 4♦],
   %w[5♠ 5♥ 5♣ 5♦], %w[6♠ 6♥ 6♣ 6♦],
   %w[7♠ 7♥ 7♣ 7♦], %w[8♠ 8♥ 8♣ 8♦],
   %w[9♠ 9♥ 9♣ 9♦], %w[T♠ T♥ T♣ T♦],
   %w[J♠ J♥ J♣ J♦], %w[Q♠ Q♥ Q♣ Q♦],
   %w[K♠ K♥ K♣ K♦], %w[??]]
end

.value(card, count_method, total) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/blackjack/card.rb', line 24

def self.value(card, count_method, total)
  value = card.value.succ
  value = 10 if value > 9
  return 11 if value == 1 && count_method == :soft && total < 11

  value
end

Instance Method Details

#ace?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/blackjack/card.rb', line 16

def ace?
  value.zero?
end

#ten?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/blackjack/card.rb', line 20

def ten?
  value > 8
end

#to_sObject



12
13
14
# File 'lib/blackjack/card.rb', line 12

def to_s
  (blackjack.face_type == 1 ? Card.faces : Card.faces2)[value][suit]
end