Class: RpgLib::RollSet
- Inherits:
-
Object
- Object
- RpgLib::RollSet
- Defined in:
- lib/rpg_lib/roll_set.rb
Overview
RollSet
Instance Attribute Summary collapse
-
#rolls ⇒ Object
readonly
Returns the value of attribute rolls.
Instance Method Summary collapse
- #add(r) ⇒ Object
- #empty? ⇒ Boolean
- #include?(roll) ⇒ Boolean
-
#initialize(*args) ⇒ RollSet
constructor
A new instance of RollSet.
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ RollSet
Returns a new instance of RollSet.
27 28 29 30 |
# File 'lib/rpg_lib/roll_set.rb', line 27 def initialize(*args) @rolls = Set.new args.each { |a| add(a) } end |
Instance Attribute Details
#rolls ⇒ Object (readonly)
Returns the value of attribute rolls.
25 26 27 |
# File 'lib/rpg_lib/roll_set.rb', line 25 def rolls @rolls end |
Instance Method Details
#add(r) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rpg_lib/roll_set.rb', line 40 def add(r) if r.is_a?(Integer) @rolls.add(r) elsif r.is_a?(Range) r.to_a.map { |e| @rolls.add(e) } elsif r.is_a?(RollSet) @rolls.merge(r.rolls) else raise Exception, "Invalid type (#{r.class}) added to roll set" end end |
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/rpg_lib/roll_set.rb', line 32 def empty? @rolls.empty? end |
#include?(roll) ⇒ Boolean
36 37 38 |
# File 'lib/rpg_lib/roll_set.rb', line 36 def include?(roll) @rolls.include?(roll) end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/rpg_lib/roll_set.rb', line 52 def to_s @rolls.to_a.join(', ') end |