Class: Ruboty::Roll::DiceSet

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/roll/dice_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count:, max:) ⇒ DiceSet

Returns a new instance of DiceSet.



9
10
11
12
# File 'lib/ruboty/roll/dice_set.rb', line 9

def initialize(count:, max:)
  @count = count
  @max   = max
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



7
8
9
# File 'lib/ruboty/roll/dice_set.rb', line 7

def count
  @count
end

#maxObject (readonly)

Returns the value of attribute max.



7
8
9
# File 'lib/ruboty/roll/dice_set.rb', line 7

def max
  @max
end

Instance Method Details

#rollObject



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

def roll
  # SecureRandom.random_number returns a value between 0 and argument - 1
  numbers = count.times.map{  SecureRandom.random_number(max) + 1 }
  Ruboty::Roll::Result.new(numbers)
end