dirceu (owner)

Revisions

  • 7ba956 Tue Jul 22 20:35:38 -0700 2008
gist: 1508 Download_button fork
public
Public Clone URL: git://gist.github.com/1508.git
Embed All Files: show embed
dices.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Author: Dirceu Pereira Tiegs <dirceutiegs@gmail.com>
#
# Script to roll dices (used to play D&D). Example:
#
# >> require 'dices'
# >> 3.d6
# => 10
# >> 3.d6+7
# => 14
# >> 1.d4+2.d8+1.d12+3
# => 32
#
 
class Numeric
  def method_missing(methodname, *args)
    dice = methodname.to_s
    if %w[d2 d3 d4 d6 d8 d10 d12 d20 d100].include? dice
      self * (rand(dice[1..4]) + 1)
    else
      self.send(methodname, *args)
    end
  end
end