Class: CalendariumRomanum::Enum

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/calendarium-romanum/enum.rb

Overview

Utility class for definition of enumerated “types”

Direct Known Subclasses

Colours, Data, Ranks, Seasons

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.allObject (readonly)

Returns the value of attribute all.



25
26
27
# File 'lib/calendarium-romanum/enum.rb', line 25

def all
  @all
end

Class Method Details

.values(index_by: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/calendarium-romanum/enum.rb', line 9

def values(index_by: nil)
  defined?(@indexed) && raise(RuntimeError.new('initialized repeatedly'))

  @indexed = {}
  @all = yield.freeze

  @all.each_with_index do |val, i|
    val.freeze

    key = index_by ? val.public_send(index_by) : i
    @indexed[key] = val
  end

  @indexed.freeze
end