Class: Roll

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Roll



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

#==(other) ⇒ Object



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

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

#eachObject



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

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

#explode(*values) ⇒ Object



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

#reroll(*values) ⇒ Object



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

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