class Blackjack::Card
Constants
- FACE_RANKS
- NUMERICAL_RANKS
- RANKS
- SUITS
- SUIT_SYMBOLS
Attributes
rank[R]
suit[R]
Public Class Methods
new(rank, suit, is_hidden = false)
click to toggle source
# File lib/blackjack/card.rb, line 18 def initialize(rank, suit, is_hidden = false) raise ArgumentError.new('Invalid rank') unless valid_rank?(rank) raise ArgumentError.new('Invalid suit') unless valid_suit?(suit) @rank = rank @suit = suit @is_hidden = is_hidden end
Public Instance Methods
ace?()
click to toggle source
# File lib/blackjack/card.rb, line 35 def ace? @rank == :ace end
equal_by_rank?(other)
click to toggle source
# File lib/blackjack/card.rb, line 43 def equal_by_rank?(other) self.rank == other.rank || self.face? && other.face? || self.rank == 10 && other.face? || self.face? && other.rank == 10 || self.ace? && other.ace? end
face?()
click to toggle source
# File lib/blackjack/card.rb, line 31 def face? FACE_RANKS.include?(@rank) end
hide()
click to toggle source
# File lib/blackjack/card.rb, line 59 def hide @is_hidden = true self end
numeric?()
click to toggle source
# File lib/blackjack/card.rb, line 27 def numeric? NUMERICAL_RANKS.include?(@rank) end
open()
click to toggle source
# File lib/blackjack/card.rb, line 64 def open @is_hidden = false self end
to_s()
click to toggle source
# File lib/blackjack/card.rb, line 51 def to_s if hidden? "[ Hidden ]" else "[ #{ @rank.to_s.capitalize } of #{ SUIT_SYMBOLS[@suit] } ]" end end
Private Instance Methods
valid_rank?(rank)
click to toggle source
# File lib/blackjack/card.rb, line 75 def valid_rank?(rank) RANKS.include?(rank) end
valid_suit?(suit)
click to toggle source
# File lib/blackjack/card.rb, line 71 def valid_suit?(suit) SUITS.include?(suit) end