Class: Ludy::DiceSet

Inherits:
Object
  • Object
show all
Defined in:
lib/ludy/dices.rb

Overview

a dice set could contain 4d6 + 2d20 and more dices.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#maxObject (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

#minObject (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

#rollObject

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