Module: Thoran::String::ToConst

Defined in:
lib/Thoran/String/ToConst/to_const.rb

Instance Method Summary collapse

Instance Method Details

#to_constObject Also known as: to_constant



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/Thoran/String/ToConst/to_const.rb', line 28

def to_const
  if self =~ /::/
    constants = self.split('::')
    constant = Object.const_get(constants.first)
    constants = constants.all_but_first
    until constants.empty? do
      constant = constant.const_get(constants.shift)
    end
  else
    constant = Object.const_get(self)
  end
  constant
end