class DiceBox::Cup
Commodity class to use multiple Dice
instances at the same time
Attributes
dices[RW]
@!attribute [rw] dices @return [Array] the Array of Dices
result[R]
@!attribute [r] result @return [Integer] the result from the previous roll
rolled[R]
@!attribute [r] result @return [Integer] the result from the previous roll
rolled_sides[R]
@!attribute [r] rolled_sides
@return [Array] the last rolled Sides of each Dice
rolled_value[R]
@!attribute [r] result @return [Integer] the result from the previous roll
Public Class Methods
new(dices = [])
click to toggle source
@param dices [Array] an Array of Dices to put in the Cup
# File lib/dice_box/cup.rb, line 19 def initialize(dices = []) @dices = dices @rolled_sides = [] end
Public Instance Methods
maximum()
click to toggle source
Returns the highest value the Cup
can roll @return [Integer] minimum roll value
# File lib/dice_box/cup.rb, line 35 def maximum dices.map(&:maximum).reduce(:+) end
Also aliased as: max
minimum()
click to toggle source
Returns the lowest value the Cup
can roll @return [Integer] minimum roll value
# File lib/dice_box/cup.rb, line 42 def minimum dices.map(&:minimum).reduce(:+) end
Also aliased as: min
roll()
click to toggle source
Rolls all the Dices in the Cup
@return [Integer] the sum of the rolled Dices
# File lib/dice_box/cup.rb, line 26 def roll @result = dices.map { |dice| dice.roll }.reduce(&:+) @rolled_sides = dices.map(&:rolled_side) result end