Class: RolledDice

Inherits:
Object
  • Object
show all
Defined in:
lib/rolled_dice.rb

Overview

This class represents the result of a roll, for people that need to work wit dice details.

Author:

  • Cédric ZUGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rolls) ⇒ RolledDice

Create a RolledDice object

Parameters:

  • rolls (Array)

    an array of integer containing the dice rolls.



11
12
13
14
# File 'lib/rolled_dice.rb', line 11

def initialize(rolls)
  @rolls = rolls
  @result = rolls.reduce(:+)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/rolled_dice.rb', line 6

def result
  @result
end

#rollsObject (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

Parameters:

  • rolled_dice (RolledDice)

    the other RolledDice to compare

Returns:

  • (Boolean)

    the result of the comparison



21
22
23
# File 'lib/rolled_dice.rb', line 21

def ==(rolled_dice)
  @rolls == rolled_dice.rolls && @result == rolled_dice.result
end