class Natural20::DieRoll::DieRolls

Attributes

rolls[RW]

Public Class Methods

new(rolls = []) click to toggle source
# File lib/natural_20/die_roll.rb, line 80
def initialize(rolls = [])
  @rolls = rolls
end

Public Instance Methods

+(other) click to toggle source
# File lib/natural_20/die_roll.rb, line 92
def +(other)
  if other.is_a?(Natural20::DieRoll)
    @rolls << other
  elsif other.is_a?(DieRolls)
    @rolls += other.rolls
  end
end
==(other) click to toggle source
# File lib/natural_20/die_roll.rb, line 106
def ==(other)
  return false if other.rolls.size != @rolls.size

  @rolls.each_with_index do |roll, index|
    return false if other.rolls[index] != roll
  end

  true
end
add_to_front(die_roll) click to toggle source
# File lib/natural_20/die_roll.rb, line 84
def add_to_front(die_roll)
  if die_roll.is_a?(Natural20::DieRoll)
    @rolls.unshift(die_roll)
  elsif die_roll.is_a?(DieRolls)
    @rolls = die_roll.rolls + @rolls
  end
end
result() click to toggle source
# File lib/natural_20/die_roll.rb, line 100
def result
  @rolls.inject(0) do |sum, roll|
    sum + roll.result
  end
end
to_s() click to toggle source
# File lib/natural_20/die_roll.rb, line 116
def to_s
  @rolls.map(&:to_s).join(' + ')
end