public Method

Module.local_constants

Return the constants that have been defined locally by this object and not in an ancestor. This method is exact if running under Ruby 1.9. In previous versions it may miss some constants if their definition in some ancestor is identical to their definition in the receiver.

Source Code

# File active_support/core_ext/module/introspection.rb, line 27
def local_constants
  inherited = {}

  ancestors.each do |anc|
    next if anc == self
    anc.constants.each { |const| inherited[const] = anc.const_get(const) }
  end

  constants.select do |const|
    !inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
  end
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.