public Method

Dependencies.qualified_const_defined?(path)

Is the provided constant path defined?

Source Code

# File active_support/dependencies.rb, line 113
def qualified_const_defined?(path)
  raise NameError, "#{path.inspect} is not a valid constant name!" unless
    /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ path

  names = path.to_s.split('::')
  names.shift if names.first.empty?

  # We can't use defined? because it will invoke const_missing for the parent
  # of the name we are checking.
  names.inject(Object) do |mod, name|
    return false unless mod.const_defined? name
    mod.const_get name
  end
  return true
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.