class EightySixed::Hand
Constants
- NON_NUMERICS
Public Class Methods
new(cards)
click to toggle source
# File lib/eighty_sixed.rb, line 9 def initialize(cards) @cards = cards @total = nil @aces = 0 end
Public Instance Methods
best_total()
click to toggle source
# File lib/eighty_sixed.rb, line 15 def best_total @total ||= calculate_total end
Private Instance Methods
aces()
click to toggle source
# File lib/eighty_sixed.rb, line 33 def aces @aces end
add(value)
click to toggle source
# File lib/eighty_sixed.rb, line 37 def add(value) @total += value end
add_values_for(cards)
click to toggle source
# File lib/eighty_sixed.rb, line 56 def add_values_for(cards) cards.each do |card| if NON_NUMERICS.include? card add(10) elsif card == "A" increment_ace_count add(11) else add(card.to_i) end end end
adjust_aces()
click to toggle source
# File lib/eighty_sixed.rb, line 69 def adjust_aces (1..aces).each do |ace| break if total <= 21 minus(10) end end
calculate_total()
click to toggle source
# File lib/eighty_sixed.rb, line 49 def calculate_total initialise_total add_values_for(@cards) adjust_aces total end
cards()
click to toggle source
# File lib/eighty_sixed.rb, line 21 def cards @cards end
increment_ace_count()
click to toggle source
# File lib/eighty_sixed.rb, line 45 def increment_ace_count @aces += 1 end
initialise_total()
click to toggle source
# File lib/eighty_sixed.rb, line 25 def initialise_total @total = 0 end
minus(value)
click to toggle source
# File lib/eighty_sixed.rb, line 41 def minus(value) @total -= value end
total()
click to toggle source
# File lib/eighty_sixed.rb, line 29 def total @total end