dice 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +15 -0
  2. data/lib/dice.rb +19 -10
  3. metadata +5 -4
@@ -0,0 +1,15 @@
1
+ =Dice
2
+
3
+ $ sudo gem install dice
4
+ $ roll D20
5
+ [18]
6
+ $ roll D20x3
7
+ [7, 8, 3]
8
+
9
+ $ irb
10
+ >> require 'dice'
11
+ => true
12
+ >> D20
13
+ => [12]
14
+ >> D20x3
15
+ => [9, 13, 6]
@@ -1,23 +1,32 @@
1
- def Object.const_missing name
2
- if name.to_s =~ /^D(\d+)$/
3
- Die.new($1).roll
4
- elsif name.to_s =~ /^D(\d+)x(\d+)$/
5
- Die.new($1).roll($2)
6
- else
7
- super
8
- end
9
- end
10
-
1
+ # Super-simple dice roller. Get your nerd on.
11
2
  class Die
12
3
 
4
+ # set up a die
13
5
  def initialize sides=20
14
6
  @sides = sides.to_i
15
7
  end
16
8
 
9
+ # roll a given number of these dice
17
10
  def roll number = 1
18
11
  rolls = []
19
12
  number.to_i.times { rolls << (rand(@sides) + 1).to_i }
20
13
  rolls
21
14
  end
22
15
 
16
+ module Roller
17
+
18
+ def const_missing name
19
+ if name.to_s =~ /^D(\d+)$/
20
+ Die.new($1).roll
21
+ elsif name.to_s =~ /^D(\d+)x(\d+)$/
22
+ Die.new($1).roll($2)
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ end
29
+
23
30
  end
31
+
32
+ Object.send :extend, Die::Roller
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -19,10 +19,11 @@ executables:
19
19
  - roll
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
24
  files:
25
25
  - lib/dice.rb
26
+ - README.rdoc
26
27
  has_rdoc: true
27
28
  homepage:
28
29
  licenses: []
@@ -47,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
48
  requirements: []
48
49
 
49
50
  rubyforge_project:
50
- rubygems_version: 1.3.3
51
+ rubygems_version: 1.3.5
51
52
  signing_key:
52
53
  specification_version: 3
53
54
  summary: Dice are delicious!