Class: PlayingCards::Card

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

Constant Summary collapse

SUITS =
%w(hearts clubs spades diamonds).map(&:to_sym)
RANKS =
%w(ace two three four five six seven eight nine ten jack queen king).map(&:to_sym)
VALUES =
%w(11 2 3 4 5 6 7 8 9 10 10 10 10)
SBITS =
%w(B D A C)
RBITS =
%w(1 2 3 4 5 6 7 8 9 A B D E)

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



6
7
8
# File 'lib/playing_cards/card.rb', line 6

def rank
  @rank
end

#suitObject

Returns the value of attribute suit

Returns:

  • (Object)

    the current value of suit



6
7
8
# File 'lib/playing_cards/card.rb', line 6

def suit
  @suit
end

Instance Method Details

#backside_to_unicodeObject



23
24
25
# File 'lib/playing_cards/card.rb', line 23

def backside_to_unicode
  "\u{1F0A0}"
end

#to_sObject



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

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

#to_unicodeObject Also known as: inspect



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

def to_unicode
  ["1F0#{suit_bit}#{rank_bit}".hex].pack("U")
end

#valueObject



27
28
29
# File 'lib/playing_cards/card.rb', line 27

def value
  VALUES[RANKS.index(rank)].to_i
end