Class: Dicey::StaticDie
- Inherits:
-
AbstractDie
- Object
- AbstractDie
- Dicey::StaticDie
- Defined in:
- lib/dicey/static_die.rb
Overview
Note:
Unlike other dice, +roll+ing a static die does not advance shared randomness generator, thus it does not have any impact on rolling other dice.
Static die has only one side and always returns the same value. Useful to model constants in dice expressions.
Instance Attribute Summary collapse
-
#value ⇒ Any
(also: #current, #next, #roll)
readonly
Die's only value.
Attributes inherited from AbstractDie
Instance Method Summary collapse
-
#initialize(value) ⇒ StaticDie
constructor
A new instance of StaticDie.
-
#to_s ⇒ String
Return a string representing the die.
Methods inherited from AbstractDie
#==, describe, #eql?, from_count, from_list, #hash, #numeric?, rand, srand
Constructor Details
#initialize(value) ⇒ StaticDie
Returns a new instance of StaticDie.
19 20 21 22 |
# File 'lib/dicey/static_die.rb', line 19 def initialize(value) @value = value super([@value].freeze) end |
Instance Attribute Details
#value ⇒ Any (readonly) Also known as: current, next, roll
Die's only value.
16 17 18 |
# File 'lib/dicey/static_die.rb', line 16 def value @value end |
Instance Method Details
#to_s ⇒ String
Return a string representing the die.
Static dice are represented with a "+" or "-" followed by the absolute value (except 0 which doesn't have a sign).
34 35 36 |
# File 'lib/dicey/static_die.rb', line 34 def to_s (!@value.respond_to?(:positive?) || @value.positive?) ? "+#{@value}" : @value.to_s end |