Class: BCDice::CommonCommand::UpperDice::Node::Dice
- Inherits:
-
Object
- Object
- BCDice::CommonCommand::UpperDice::Node::Dice
- Defined in:
- lib/bcdice/common_command/upper_dice/node.rb
Instance Method Summary collapse
-
#initialize(roll_times, sides) ⇒ Dice
constructor
A new instance of Dice.
- #roll(randomizer, reroll_threshold, sort) ⇒ Array<Hash>
- #to_s ⇒ String
Constructor Details
#initialize(roll_times, sides) ⇒ Dice
Returns a new instance of Dice.
137 138 139 140 |
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 137 def initialize(roll_times, sides) @roll_times = roll_times @sides = sides end |
Instance Method Details
#roll(randomizer, reroll_threshold, sort) ⇒ Array<Hash>
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 146 def roll(randomizer, reroll_threshold, sort) ret = Array.new(@roll_times) do list = roll_ones(randomizer, reroll_threshold) {sum: list.sum(), list: list} end if sort ret = ret.sort_by { |e| e[:sum] } end return ret end |
#to_s ⇒ String
160 161 162 |
# File 'lib/bcdice/common_command/upper_dice/node.rb', line 160 def to_s "#{@roll_times}U#{@sides}" end |