Class: BagOfHolding::Dice::DieResult

Inherits:
Object
  • Object
show all
Defined in:
lib/bag_of_holding/dice/die_result.rb

Overview

Internal: Encapsulate the value of a die roll along with the rolls that where performed to achieve that value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rolls: nil, value: nil, die: nil) ⇒ DieResult

Returns a new instance of DieResult.



8
9
10
11
12
# File 'lib/bag_of_holding/dice/die_result.rb', line 8

def initialize(rolls: nil, value: nil, die: nil)
  self.rolls = rolls || []
  self.value = value
  self.die = die
end

Instance Attribute Details

#dieObject

Returns the value of attribute die.



6
7
8
# File 'lib/bag_of_holding/dice/die_result.rb', line 6

def die
  @die
end

#rollsObject

Returns the value of attribute rolls.



6
7
8
# File 'lib/bag_of_holding/dice/die_result.rb', line 6

def rolls
  @rolls
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/bag_of_holding/dice/die_result.rb', line 6

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
17
18
19
# File 'lib/bag_of_holding/dice/die_result.rb', line 14

def ==(other)
  return false if value != other.value
  return false if rolls != other.rolls
  return false if die != other.die
  true
end

#add_roll(roll) ⇒ Object



21
22
23
# File 'lib/bag_of_holding/dice/die_result.rb', line 21

def add_roll(roll)
  rolls.push roll
end