Class: Enum::Base

Inherits:
BasicObject
Defined in:
lib/enum/base.rb

Class Method Summary collapse

Class Method Details

.allObject



16
17
18
# File 'lib/enum/base.rb', line 16

def all
  store.to_a
end

.inherited(child) ⇒ Object



6
7
8
9
10
# File 'lib/enum/base.rb', line 6

def inherited(child)
  return if self == Enum

  init_child_class(child)
end

.name(t) ⇒ Object



28
29
30
# File 'lib/enum/base.rb', line 28

def name(t)
  translate(take(t))
end

.take(t) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/enum/base.rb', line 20

def take(t)
  ts = t.to_s
  unless store.include?(ts)
    raise(TokenNotFoundError, "token '#{t}'' not found in the enum #{self}")
  end
  ts
end

.values(*ary) ⇒ Object



12
13
14
# File 'lib/enum/base.rb', line 12

def values(*ary)
  ary.each { |val| add_value(val.to_s) }
end