Class: Roll

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/roll.rb

Instance Method Summary (collapse)

Constructor Details

- (Roll) initialize(num_of_dice, options = { :die_size => 10, :rand_generator => Random})



4
5
6
7
8
# File 'lib/roll.rb', line 4

def initialize(num_of_dice, options = { :die_size => 10, :rand_generator => Random})
  @options = options
  @rand_generator = @options[:rand_generator]
  @dice = roll(num_of_dice)
end

Instance Method Details

- (Object) ==(other)



20
21
22
# File 'lib/roll.rb', line 20

def ==(other)
  @dice == other
end

- (Object) each



24
25
26
# File 'lib/roll.rb', line 24

def each
  @dice.each { |die| yield die }
end

- (Object) explode(*values)



15
16
17
18
# File 'lib/roll.rb', line 15

def explode(*values)
  each_die_that_matches(values) { |die| last_die = roll_die; [die + last_die, last_die] }
  self
end

- (Object) reroll(*values)



10
11
12
13
# File 'lib/roll.rb', line 10

def reroll(*values)
  each_die_that_matches(values) { roll_die }
  self
end