class Ventiuna::Card

Attributes

rank[RW]
suit[RW]

Public Class Methods

new(rank: "joker", suit: "joker") click to toggle source
# File lib/ventiuna/card.rb, line 5
def initialize(rank: "joker", suit: "joker")
        @rank = rank.to_s.upcase
        @suit = suit
end

Public Instance Methods

<=>(other_card) click to toggle source

sorts cards with Aces always high

# File lib/ventiuna/card.rb, line 23
def <=>(other_card)
        self.value(high: true) <=> other_card.value(high: true)
end
==(other_card) click to toggle source
# File lib/ventiuna/card.rb, line 27
def ==(other_card)
        self.to_s == other_card.to_s
end
ace?() click to toggle source
# File lib/ventiuna/card.rb, line 18
def ace?
        self.rank == "A"
end
to_i(high: true, low: false) click to toggle source
# File lib/ventiuna/card.rb, line 10
def to_i(high: true, low: false)
        return 1  if self.ace? && low
        return 11 if self.ace? && high
        return 10 if ["K", "Q", "J"].include?(self.rank)
        self.rank.to_i
end
Also aliased as: value
to_s() click to toggle source
# File lib/ventiuna/card.rb, line 31
def to_s
        "#{self.rank} #{self.suit}"
end
value(high: true, low: false)
Alias for: to_i