Dice is a command line dice roller using ruby's Random number generator.
$ gem install dice
Add this line to your application's Gemfile:
gem 'dice'
And then execute:
$ bundle
Dice can be used one of two ways; from the command line, or from an api call.
Once you have the gem installed or you downloaded the source from github,
https://github.com/billyogat/dice.
Execute the roll
command from you command line with a dice
argument.
$ roll 2d6
6 -- 2d6:[4, 2]
The dice argument can contain one or more dice groups.
$ roll 2d6+1d8
13 -- 2d6:[5, 5] +1d8:[3]
As well as modifiers.
$ roll 2d6+1d8+5
23 -- 2d6:[5, 6] +1d8:[7] mod:[5]
All dice groups (except for the first) and modifiers can be positive[+] or negative[-]. But the dice argument must follow this regual expression.
^\d*d\d+([+-]\d+d\d+)*([+-]\d*)*$
Verbose output is the default, if you would like only the result displayed add the --[no-]verbose
option to the
command.
$ roll --no-verbose 2d6+1d8+5
18
After adding the gem to your Gemfile you can make calls to the Roller by creating a new instances and calling {Roller#roll_dice}.
roller = Dice::Roller.new
roller.roll_dice('2d6')
=> [{"2d6"=>[2, 1]}]
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request