class Dice

Attributes

values[R]

Public Class Methods

new(values=Array.new(5) {new_dice}) click to toggle source
# File lib/dice.rb, line 5
def initialize(values=Array.new(5) {new_dice}) # @param values [Array<Fixnum>] that contains 5 Fixnums
        check_dice values
        @values = values
end

Public Instance Methods

display()
Alias for: to_s
roll(dice_to_roll) click to toggle source

@raise [ArgumentError] if i element > 4 @return [void] @param i [Array<Fixnum>] < 4

end

# File lib/dice.rb, line 15
def roll(dice_to_roll)
        for index in dice_to_roll
                raise ArgumentError, "Illegal index" if index > 4
                @values[index] = new_dice
        end
end
roll_all() click to toggle source

@note Rolls all the dice

@return [Dice]

end

# File lib/dice.rb, line 27
def roll_all
        initialize
end
to_s() click to toggle source
# File lib/dice.rb, line 32
def to_s # @return [String] instance variable dice
        print @values
end
Also aliased as: display
values=(values) click to toggle source

@param values [Array<Integer>] @see (check_dice) @note setting dice for values for testing @!parse attr_writer :values

end

# File lib/dice.rb, line 43
def values=(values)
        check_dice values
        @values = values
end

Private Instance Methods

check_dice(dice) click to toggle source

@param dice [Array<Fixnum>] @return [void] @raise [ArgumentError] if dice does not meet expectations

end

# File lib/dice.rb, line 59
def check_dice(dice)
        raise(ArgumentError, "Array must have 5 Integers that are between 1 and 6") unless dice.length == 5 && dice.all? {|val| (val.is_a? Fixnum) && (val.between? 1,6)}
end
new_dice() click to toggle source
# File lib/dice.rb, line 50
def new_dice # @return [Fixnum] a random number between 1 and 6, inclusive
        (1..6).to_a.sample
end