Class: Blackjack::Card

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rankObject

Returns the value of attribute rank

Returns:

  • (Object)

    the current value of rank



2
3
4
# File 'lib/blackjack/card.rb', line 2

def rank
  @rank
end

#suitObject

Returns the value of attribute suit

Returns:

  • (Object)

    the current value of suit



2
3
4
# File 'lib/blackjack/card.rb', line 2

def suit
  @suit
end

Instance Method Details

#ace?Boolean

:nocov:

Returns:

  • (Boolean)


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

def ace?
  rank == "A"
end

#inspectObject

:nocov:



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

def inspect
  "#{rank}#{suit[0]}"
end

#pointsObject



19
20
21
22
23
24
25
26
# File 'lib/blackjack/card.rb', line 19

def points
  if ace?
    11
  else
    # if it's not a number, it's a 10
    (rank.is_a?(Integer) || rank.to_i != 0) ? rank.to_i : 10
  end
end

#to_sObject

:nocov:



10
11
12
# File 'lib/blackjack/card.rb', line 10

def to_s
  "#{rank} of #{suit}"
end