Class: Roll

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

Instance Method Summary collapse

Constructor Details

#initializeRoll

Returns a new instance of Roll.



7
8
9
# File 'lib/craps_dice.rb', line 7

def initialize
 2.times { push(rand(1..6)) }
end

Instance Method Details

#dupObject



31
32
33
# File 'lib/craps_dice.rb', line 31

def dup
  Marshal.load(Marshal.dump(self))
end

#is_hard?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/craps_dice.rb', line 17

def is_hard?
  uniq.length == 1
end

#is_seven?Boolean

Returns:

  • (Boolean)


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

def is_seven?
  sum == 7
end

#nameObject



25
26
27
28
29
# File 'lib/craps_dice.rb', line 25

def name
  ROLL_NAMES.find { |key, values|
    values.include?(self.sort)
  }.first
end

#rerollObject



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

def reroll
  clear
 2.times { push(rand(1..6)) }
  self
end