Class: BCDice::CommonCommand::TallyDice::Node::Dice
- Inherits:
-
Object
- Object
- BCDice::CommonCommand::TallyDice::Node::Dice
- Defined in:
- lib/bcdice/common_command/tally_dice/node.rb
Overview
個数カウントダイス:ダイスのノード
Instance Attribute Summary collapse
-
#show_zeros ⇒ Boolean
(also: #show_zeros?)
readonly
個数0を表示するか.
-
#sides ⇒ Integer
readonly
面数.
-
#times ⇒ Integer
readonly
振る回数.
Instance Method Summary collapse
-
#initialize(times:, sides:, show_zeros:) ⇒ Dice
constructor
A new instance of Dice.
-
#roll(randomizer) ⇒ Array<Integer>
ダイスを振る.
- #to_s ⇒ String
-
#valid? ⇒ Boolean
ダイスとして有効(振る回数、面数ともに正の数)か.
Constructor Details
#initialize(times:, sides:, show_zeros:) ⇒ Dice
Returns a new instance of Dice.
108 109 110 111 112 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 108 def initialize(times:, sides:, show_zeros:) @times = times @sides = sides @show_zeros = show_zeros end |
Instance Attribute Details
#show_zeros ⇒ Boolean (readonly) Also known as: show_zeros?
Returns 個数0を表示するか.
102 103 104 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 102 def show_zeros @show_zeros end |
#sides ⇒ Integer (readonly)
Returns 面数.
100 101 102 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 100 def sides @sides end |
#times ⇒ Integer (readonly)
Returns 振る回数.
98 99 100 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 98 def times @times end |
Instance Method Details
#roll(randomizer) ⇒ Array<Integer>
ダイスを振る
122 123 124 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 122 def roll(randomizer) randomizer.(@times, @sides) end |
#to_s ⇒ String
127 128 129 130 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 127 def to_s show_zeros_symbol = @show_zeros ? "Z" : "Y" "#{@times}T#{show_zeros_symbol}#{@sides}" end |
#valid? ⇒ Boolean
Returns ダイスとして有効(振る回数、面数ともに正の数)か.
115 116 117 |
# File 'lib/bcdice/common_command/tally_dice/node.rb', line 115 def valid? @times > 0 && @sides > 0 end |