class Rollable::Roll

Overview

Roll is a list of Dice.

It is rollable, making the sum of each Dice values. It is also possible to get the details of a roll, using the methods .min_details, .max_details, .average_details, .test_details

Example:

r = Rollable.parse "1d6+2" # note: it also support "1d6 + 2"
r.min                      # => 3
r.max                      # => 9
r.average                  # => 5.5
r.test                     # => the sum of a random value in 1..6 and 2

Defined in:

rollable/roll.cr
rollable/roll/parse_wrap.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Rollable::IsRollable

average : Float64 average, max : Int32 max, min : Int32 min, test : Int32 test

Constructor Detail

def self.new(dice : Array(Rollable::Dice)) #

[View source]
def self.parse(str : String) : Roll #

Parse the string "str" and returns a new Roll object

see #parse_str


[View source]

Class Method Detail

def self.parse(str : String, &) : Roll | Nil #

Parse the string "str" and returns a new Roll object, and execute the "block" if an error occured


[View source]

Instance Method Detail

def <(right : Roll) #

[View source]
def <=(right : Roll) #

[View source]
def <=>(right : Roll) : Int32 #

[View source]
def ==(right : Roll) #

[View source]
def >(right : Roll) #

[View source]
def >=(right : Roll) #

[View source]
def average : Float64 #

[View source]
def average_details : Array(Float64) #

[View source]
def clone #

[View source]
def compact #

[View source]
def compact! #

let a [1d6, 1d4, 1d6, 2, 2d6] first, we copy it for 1d6 we check evey d6 in the copy, fetch and delete them


[View source]
def dice : Array(Rollable::Dice) #

[View source]
def max : Int32 #

[View source]
def max_details : Array(Int32) #

[View source]
def min : Int32 #

[View source]
def min_details : Array(Int32) #

[View source]
def order #

[View source]
def order! #

[View source]
def reverse : Roll #

Return a reversed copy of the Roll's values.

Example:

Roll.parse("1d6").reverse # => -1d6

[View source]
def reverse! : Roll #

Reverse the values of the Roll.


[View source]
def size(*args, **options) #

[View source]
def size(*args, **options, &) #

[View source]
def test : Int32 #

[View source]
def test_details : Array(Int32) #

[View source]
def to_s : String #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]