rdice 1.0.0 → 1.0.1

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.
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem "rdice"
16
16
  ## Usage
17
17
 
18
18
 
19
- Them most basic use you can create a new instance of Dice and perform some rolls. The returned value is a integer containing the sum of all dices rolled
19
+ The most basic use you can create a new instance of Dice and perform some rolls. The returned value is a integer containing the sum of all dices rolled
20
20
 
21
21
  ```ruby
22
22
  dice = Dice.new
@@ -1,27 +1,36 @@
1
1
  class Dice
2
+ # This class is responsible for default settings of Dice class
3
+ # these methods allow change the preferences of a dice and sets
4
+ # some getter methods for check preferences
2
5
  class Config
6
+ # Return the default number of dice sides
3
7
  def self.sides
4
8
  @sides
5
9
  end
6
10
 
11
+ # Set the number of dice sides
7
12
  def self.sides=(sides)
8
13
  raise ArgumentError, 'Must be a Integer' unless sides.is_a? Integer
9
14
  @sides = sides
10
15
  end
11
16
 
17
+ # Return the default number of dices rolled
12
18
  def self.dices
13
19
  @dices
14
20
  end
15
21
 
22
+ # Set the number of default dices rolled
16
23
  def self.dices=(dices)
17
24
  raise ArgumentError, 'Must be a Integer' unless dices.is_a? Integer
18
25
  @dices = dices
19
26
  end
20
27
 
28
+ # Used to check if results is an array or not. Return true if setted for array
21
29
  def self.array?
22
30
  @array || false
23
31
  end
24
32
 
33
+ # Set true or false for results in array format
25
34
  def self.array=(array)
26
35
  raise ArgumentError, 'Must be true or false' unless [true, false].include?(array)
27
36
  @array = array
@@ -1,14 +1,53 @@
1
+ # RDice
2
+ # Author:: Denis Tierno (de.tierno@gmail.com)
3
+ #
4
+ # This program is intended to allow a dice creation and perform some rolls
5
+ # the most basic use you can create a new instance of Dice and perform some rolls.
6
+ #
7
+ # Dice.new creates a object with one dice with six sides by default and the result is a Integer
8
+ #
9
+ # To change the defaults just pass it on creation
10
+ # dice = Dice.new(20,2,true)
11
+ # This will set the defaults as 2 dices with 20 sides each and result as a Array
12
+ # dice.roll # => [9, 15]
13
+ #
14
+ # To override the defaults sides and dices just write how many dices you wanna roll
15
+ # dice = Dice.new(20,2)
16
+ #
17
+ # dice.roll # rolls two d20 by default
18
+ # dice.roll_two # rolls two d20
19
+ # dice.roll_four # rolls four d20
20
+ # dice.roll_d20 # rolls two d20
21
+ # dice.roll_three_d8 # rolls three d8
22
+ # dice.roll_10_d3 # rolls 10 d3
23
+
1
24
  class Dice
25
+ # Set the defaults values for Dice object
2
26
  def initialize(sides=6, dices=1, array=false)
3
27
  Dice::Config.sides = sides
4
28
  Dice::Config.dices = dices
5
29
  Dice::Config.array = array
6
30
  end
7
-
31
+
32
+ # To perform a roll without use method missing exception call <tt>roll</tt>
33
+ # with desired number of sides and dices.
34
+ # First argument is an integer with number of dice sides and
35
+ # second is an integer with the number of dices rolled by default.
36
+ # Result can be a sum or a array.
8
37
  def roll(sides=preferred_sides, dices=preferred_dices)
9
38
  get_result(sides, dices)
10
39
  end
11
40
 
41
+ # Provides some handy shortcuts for a Dice object allowing to call
42
+ # methods like:
43
+ #
44
+ # dice = Dice.new
45
+ #
46
+ # dice.roll
47
+ # dice.roll_two
48
+ # dice.roll_d20
49
+ # dice.roll_three_d8
50
+ # dice.roll_10_d3
12
51
  def method_missing(method, *args, &block)
13
52
  if method =~ /roll_d(\w+)/
14
53
  roll($1.to_i)
@@ -1,3 +1,3 @@
1
1
  class Dice
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdice
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70235608766060 !ruby/object:Gem::Requirement
16
+ requirement: &70219989185120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70235608766060
24
+ version_requirements: *70219989185120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70235608765140 !ruby/object:Gem::Requirement
27
+ requirement: &70219989182020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70235608765140
35
+ version_requirements: *70219989182020
36
36
  description: ! 'This gem allow you to set dices and roll it. You can set custom defaults
37
37
  and change behavior to fit your purpose '
38
38
  email:
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: 747301994299439198
73
+ hash: -2035843853156825772
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 747301994299439198
82
+ hash: -2035843853156825772
83
83
  requirements: []
84
84
  rubyforge_project: rdice
85
85
  rubygems_version: 1.8.10