class Rollable::Die
- Rollable::Die
- Rollable::IsRollable
- Reference
- Object
Overview
Not a front class. It is used to represent a type of dice with faces
A Die
is a range of Integer values.
It is rollable.
Example:
d = Die.new(1..6)
d.min # => 1
d.max # => 6
d.average # => 3.5
d.test # => a random value included in 1..6
TODO make it a Struct ?
Defined in:
rollable/die.crConstant Summary
-
EXPLODING_ITERATIONS =
4
-
MAX =
1000
Constructors
- .new(nb_faces : Int32, exploding : Bool = false)
- .new(faces : Range(Int32, Int32), exploding : Bool = false)
Instance Method Summary
- #<(right : Die)
- #<=(right : Die)
- #<=>(right : Die) : Int32
- #==(right : Die)
- #>(right : Die)
- #>=(right : Die)
-
#average : Float64
Mathematical expectation.
- #clone
- #exploding : Bool
- #faces : Range(Int32, Int32)
- #fixed?
- #like?(other : Die)
- #max : Int32
- #min : Int32
- #negative?
-
#reverse : Die
Reverse the values
- #reverse!
-
#size
Number of faces of the
Die
-
#test : Int32
Return a random value in the range of the dice
-
#to_s : String
Return a string.
Instance methods inherited from class Rollable::IsRollable
average : Float64
average,
max : Int32
max,
min : Int32
min,
test : Int32
test
Constructor Detail
Instance Method Detail
Reverse the values
Example:
Die.new(1..6).reverse # => Die.new -6..-1
def to_s : String
#
Return a string.
- It may be a fixed value
(n..n) => "#{n}"
- It may be a dice
(1..n) => "D#{n}"
- Else,
(a..b) => "D(#{a},#{b})"