Class: RpgLib::RollSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rpg_lib/roll_set.rb

Overview

RollSet

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rollsObject (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

Returns:

  • (Boolean)


32
33
34
# File 'lib/rpg_lib/roll_set.rb', line 32

def empty?
  @rolls.empty?
end

#include?(roll) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rpg_lib/roll_set.rb', line 36

def include?(roll)
  @rolls.include?(roll)
end

#to_sObject



52
53
54
# File 'lib/rpg_lib/roll_set.rb', line 52

def to_s
  @rolls.to_a.join(', ')
end