Sha256: ff33d855b8342e8d28e1adffed43fb5d835e79993525787a4adfed2f67c7c29f

Contents?: true

Size: 703 Bytes

Versions: 2

Compression:

Stored size: 703 Bytes

Contents

require 'dmorrill10-utils/class'

require 'delegate'

class AcpcPokerTypes::ChipStack < DelegateClass(Rational)
  exceptions :illegal_number_of_chips

  # @param [#to_i] number_of_chips The number of chips to be made into a stack.
  # @raise (see #assert_valid_value)
  def initialize(number_of_chips=0)
    @value = number_of_chips.to_i

    assert_valid_value

    super @value
  end

  def receive!(number_of_chips)
    @value += number_of_chips

    assert_valid_value

    __setobj__ @value

    self
  end
  def give!(number_of_chips)
    receive!(-number_of_chips)
  end

  private

  # @raise IllegalNumberOfChips
  def assert_valid_value
    raise IllegalNumberOfChips if @value < 0
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acpc_poker_types-2.0.0 lib/acpc_poker_types/chip_stack.rb
acpc_poker_types-1.0.0 lib/acpc_poker_types/chip_stack.rb