Class: Randsum::Roll

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(die:, quantity:, result: nil) ⇒ Roll

Returns a new instance of Roll.



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

def initialize(die:, quantity:, result: nil)
  @die = die
  @quantity = quantity
  @sides = die.sides
  @result = result || roll!
end

Instance Attribute Details

#dieObject (readonly)

Returns the value of attribute die.



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

def die
  @die
end

#quantityObject (readonly) Also known as: length, count

Returns the value of attribute quantity.



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

def quantity
  @quantity
end

#resultObject (readonly) Also known as: rolls

Returns the value of attribute result.



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

def result
  @result
end

#sidesObject (readonly)

Returns the value of attribute sides.



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

def sides
  @sides
end

#totalObject (readonly) Also known as: to_i

Returns the value of attribute total.



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

def total
  @total
end

Instance Method Details

#drop(quantity:, extremity:) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/randsum/roll.rb', line 27

def drop(quantity:,extremity:)
  return new_roll_with(
  result: Dropper.dropper_for(
      quantity: quantity,
      extremity: extremity,
      rolls: result
    ).filter
  )
end

#drop_highest(quantity = 1) ⇒ Object



41
42
43
# File 'lib/randsum/roll.rb', line 41

def drop_highest(quantity = 1)
  drop(quantity: quantity, extremity: :highest)
end

#drop_lowest(quantity = 1) ⇒ Object



37
38
39
# File 'lib/randsum/roll.rb', line 37

def drop_lowest(quantity = 1)
  drop(quantity: quantity, extremity: :lowest)
end

#to_sObject Also known as: inspect



17
18
19
# File 'lib/randsum/roll.rb', line 17

def to_s
  "You rolled #{count} #{die}, and got #{total}. (Rolls: #{result})"
end