Module: Noumenon::StringExtensions

Defined in:
lib/noumenon/string_extensions.rb

Overview

Adds some additional methods to String objects.

Instance Method Summary collapse

Instance Method Details

#constantizeObject

Attempts to convert a string into a constant.

If the constant could not be found then a NameError will be raised.

Examples:

"Foo::Bar".constantize # => Foo::Bar


11
12
13
14
15
16
17
18
# File 'lib/noumenon/string_extensions.rb', line 11

def constantize
  mod = Module
  split("::").each do |mod_name|
    mod = mod.const_get(mod_name.to_sym)
  end

  mod
end