Class: Ludy::DiceSet
- Inherits:
-
Object
- Object
- Ludy::DiceSet
- Defined in:
- lib/ludy/dices.rb
Overview
a dice set could contain 4d6 + 2d20 and more dices.
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
the min and max possible value of this dice set.
-
#min ⇒ Object
readonly
the min and max possible value of this dice set.
Instance Method Summary collapse
-
#<<(dices) ⇒ Object
put dices into this dice set.
-
#initialize(*args) ⇒ DiceSet
constructor
A new instance of DiceSet.
-
#roll ⇒ Object
roll the dice set.
Constructor Details
#initialize(*args) ⇒ DiceSet
Returns a new instance of DiceSet.
27 28 29 30 31 32 33 34 |
# File 'lib/ludy/dices.rb', line 27 def initialize *args @diceset = args @min = @max = 0 @diceset.each{ |i| @min += i.min @max += i.max } end |
Instance Attribute Details
#max ⇒ Object (readonly)
the min and max possible value of this dice set.
26 27 28 |
# File 'lib/ludy/dices.rb', line 26 def max @max end |
#min ⇒ Object (readonly)
the min and max possible value of this dice set.
26 27 28 |
# File 'lib/ludy/dices.rb', line 26 def min @min end |
Instance Method Details
#<<(dices) ⇒ Object
put dices into this dice set
42 43 44 45 46 47 |
# File 'lib/ludy/dices.rb', line 42 def << dices @diceset << dices @min += dices.min @max += dices.max self end |
#roll ⇒ Object
roll the dice set
36 37 38 39 40 |
# File 'lib/ludy/dices.rb', line 36 def roll result = 0 @diceset.each { |i| result += i.roll } result end |