Module: Ruby::Enum::ClassMethods

Defined in:
lib/ruby-enum/enum.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(key) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/ruby-enum/enum.rb', line 22

def const_missing(key)
  if @hash[key]
    @hash[key].value
  else
    raise Ruby::Enum::Errors::UninitializedConstantError.new({ :name => name, :key => key })
  end
end

#define(key, value) ⇒ Object



17
18
19
20
# File 'lib/ruby-enum/enum.rb', line 17

def define(key, value)
  @hash ||= {}
  @hash[key] = self.new(key, value)
end

#each(&block) ⇒ Object



30
31
32
33
34
# File 'lib/ruby-enum/enum.rb', line 30

def each(&block)
  @hash.each do |key, value|
    yield key, value
  end
end

#parse(s) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/ruby-enum/enum.rb', line 36

def parse(s)
  s = s.to_s.upcase
  each do |key, value|
    if key.to_s.upcase == s
      return value.value
    end
  end
  nil
end