Class: BagOfHolding::Dice::DieResult
- Inherits:
-
Object
- Object
- BagOfHolding::Dice::DieResult
- 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
-
#die ⇒ Object
Returns the value of attribute die.
-
#rolls ⇒ Object
Returns the value of attribute rolls.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_roll(roll) ⇒ Object
-
#initialize(rolls: nil, value: nil, die: nil) ⇒ DieResult
constructor
A new instance of DieResult.
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
#die ⇒ Object
Returns the value of attribute die.
6 7 8 |
# File 'lib/bag_of_holding/dice/die_result.rb', line 6 def die @die end |
#rolls ⇒ Object
Returns the value of attribute rolls.
6 7 8 |
# File 'lib/bag_of_holding/dice/die_result.rb', line 6 def rolls @rolls end |
#value ⇒ Object
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 |