Class: Tabletop::FudgeDie

Inherits:
Die
  • Object
show all
Defined in:
lib/tabletop/randomizers.rb

Overview

A FudgeDie is a kind of three-sided Die that has a value of either 0, 1, or -1.

Instance Attribute Summary

Attributes inherited from Die

#sides, #value

Instance Method Summary collapse

Methods inherited from Die

#<=>, new_from_string, #to_int

Constructor Details

#initialize(params = {}) ⇒ FudgeDie

Returns a new instance of FudgeDie.



68
69
70
# File 'lib/tabletop/randomizers.rb', line 68

def initialize(params = {})
  super(sides: 3, value: params[:value])
end

Instance Method Details

#rollObject



71
72
73
# File 'lib/tabletop/randomizers.rb', line 71

def roll
  @value = rand(sides)-1
end

#to_sObject

Returns either “[-]”, “[ ]”, or “[+]”, depending on @value



76
77
78
# File 'lib/tabletop/randomizers.rb', line 76

def to_s
  "[#{['-', ' ', '+'][@value+1]}]"
end