lib/games_dice/die.rb in games_dice-0.3.7 vs lib/games_dice/die.rb in games_dice-0.3.8
- old
+ new
@@ -66,9 +66,22 @@
else
@result = rand(@sides) + 1
end
end
+ # Iterates through all possible results on die.
+ # @yieldparam [Integer] result A potential result from the die
+ # @return [GamesDice::Die] this object
+ def each_value
+ (1..@sides).each { |r| yield(r) }
+ self
+ end
+
+ # @return [Array<Integer>] All potential results from the die
+ def all_values
+ (1..@sides).to_a
+ end
+
# @!attribute [r] rerolls
# Rules for when to re-roll this die.
# @return [nil] always nil, available for interface equivalence with GamesDice::ComplexDie
def rerolls
nil