Class: RubyPlayingCards::Card

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

Constant Summary collapse

FACE_CARDS =
{ 1 => :A, 13 => :K, 12 => :Q, 11 => :J }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank, suit) ⇒ Card

Returns a new instance of Card.



8
9
10
11
# File 'lib/ruby_playing_cards/card.rb', line 8

def initialize(rank, suit)
  @rank = FACE_CARDS[rank] || rank
  @suit = suit
end

Instance Attribute Details

#rankObject

Returns the value of attribute rank.



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

def rank
  @rank
end

#suitObject

Returns the value of attribute suit.



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

def suit
  @suit
end

Instance Method Details

#to_sObject



13
14
15
# File 'lib/ruby_playing_cards/card.rb', line 13

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