Class: GooseGame::Dice

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

Constant Summary collapse

QTY =
2
MAX =
6

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(d1 = 0, d2 = 0) ⇒ Dice

Returns a new instance of Dice.



12
13
14
# File 'lib/goose_game/dice.rb', line 12

def initialize(d1 = 0, d2 = 0)
  @d1, @d2 = *check_args(d1, d2)
end

Instance Attribute Details

#d1Object (readonly)

Returns the value of attribute d1.



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

def d1
  @d1
end

#d2Object (readonly)

Returns the value of attribute d2.



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

def d2
  @d2
end

Class Method Details

.rollObject



8
9
10
# File 'lib/goose_game/dice.rb', line 8

def self.roll
  new(*QTY.times.map { |_| rand(MAX) + 1 })
end

Instance Method Details

#to_iObject



16
17
18
# File 'lib/goose_game/dice.rb', line 16

def to_i
  [d1, d2].sum
end