Class: RolledDice
- Inherits:
-
Object
- Object
- RolledDice
- Defined in:
- lib/rolled_dice.rb
Overview
This class represents the result of a roll, for people that need to work wit dice details.
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#rolls ⇒ Object
readonly
Returns the value of attribute rolls.
Instance Method Summary collapse
-
#==(rolled_dice) ⇒ Boolean
Compare two rolls.
-
#initialize(rolls) ⇒ RolledDice
constructor
Create a RolledDice object.
Constructor Details
#initialize(rolls) ⇒ RolledDice
Create a RolledDice object
11 12 13 14 |
# File 'lib/rolled_dice.rb', line 11 def initialize(rolls) @rolls = rolls @result = rolls.reduce(:+) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/rolled_dice.rb', line 6 def result @result end |
#rolls ⇒ Object (readonly)
Returns the value of attribute rolls.
6 7 8 |
# File 'lib/rolled_dice.rb', line 6 def rolls @rolls end |
Instance Method Details
#==(rolled_dice) ⇒ Boolean
Compare two rolls
21 22 23 |
# File 'lib/rolled_dice.rb', line 21 def ==(rolled_dice) @rolls == rolled_dice.rolls && @result == rolled_dice.result end |