class Randsum::Roll

Attributes

count[R]
die[R]
length[R]
quantity[R]
result[R]
rolls[R]
sides[R]
to_i[R]
total[R]

Public Class Methods

new(die:, quantity:, result: nil) click to toggle source
# File lib/randsum/roll.rb, line 13
def initialize(die:, quantity:, result: nil)
  @die = die
  @quantity = quantity
  @sides = die.sides
  @result = result || roll!
end
roll(num, d:) click to toggle source
# File lib/randsum/roll.rb, line 9
def self.roll(num, d:)
  new(die: Die.new(d), quantity: num)
end

Public Instance Methods

beats?(check_value) click to toggle source
# File lib/randsum/roll.rb, line 30
def beats?(check_value)
  total > check_value
end
double_all(target) click to toggle source
# File lib/randsum/roll.rb, line 46
def double_all(target)
  Replacer.for(
    target: target,
    with: ReplacerValue::DOUBLE,
    roll: self
  ).filter
end
drop(quantity:,extremity:) click to toggle source
# File lib/randsum/roll.rb, line 62
def drop(quantity:,extremity:)
  Dropper.for(
    quantity: quantity,
    extremity: extremity,
    roll: self
  ).filter
end
drop_highest(quantity = 1) click to toggle source
# File lib/randsum/roll.rb, line 74
def drop_highest(quantity = 1)
  drop(quantity: quantity, extremity: :highest)
end
drop_lowest(quantity = 1) click to toggle source
# File lib/randsum/roll.rb, line 70
def drop_lowest(quantity = 1)
  drop(quantity: quantity, extremity: :lowest)
end
inspect()
Alias for: to_s
meets?(meet_value) click to toggle source
# File lib/randsum/roll.rb, line 34
def meets?(meet_value)
  total >= meet_value
end
replace(target, with:) click to toggle source
# File lib/randsum/roll.rb, line 38
def replace(target, with:)
  Replacer.for(
    target: target,
    with: with,
    roll: self
  ).filter
end
reroll() click to toggle source
# File lib/randsum/roll.rb, line 54
def reroll
  Replacer.for(
    target: ReplacerTarget::ALL,
    with: ReplacerValue::REROLL,
    roll: self
  ).filter
end
to_s() click to toggle source
# File lib/randsum/roll.rb, line 20
def to_s
  "You rolled #{count} #{die}, and got #{total}. (Rolls: #{result})"
end
Also aliased as: inspect

Private Instance Methods

roll!() click to toggle source
# File lib/randsum/roll.rb, line 80
def roll!
  (1..quantity).map { die.simple_roll }
end