mirror of
https://github.com/github/rails.git
synced 2026-02-16 09:05:14 -05:00
Ruby 1.9: Module#local_constants can now just use constants(false). Closes #10648 [Xavier Noria]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8555 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -5,7 +5,7 @@ class Module
|
||||
parent_name = name.split('::')[0..-2] * '::'
|
||||
parent_name.empty? ? Object : parent_name.constantize
|
||||
end
|
||||
|
||||
|
||||
# Return all the parents of this module, ordered from nested outwards. The
|
||||
# receiver is not contained within the result.
|
||||
def parents
|
||||
@@ -18,18 +18,27 @@ class Module
|
||||
parents << Object unless parents.include? Object
|
||||
parents
|
||||
end
|
||||
|
||||
# Return the constants that have been defined locally by this object and not
|
||||
# in an ancestor. This method may miss some constants if their definition in
|
||||
# the ancestor is identical to their definition in the receiver.
|
||||
def local_constants
|
||||
inherited = {}
|
||||
ancestors.each do |anc|
|
||||
next if anc == self
|
||||
anc.constants.each { |const| inherited[const] = anc.const_get(const) }
|
||||
|
||||
if RUBY_VERSION < '1.9'
|
||||
# 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.
|
||||
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
|
||||
constants.select do |const|
|
||||
! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
|
||||
else
|
||||
def local_constants #:nodoc:
|
||||
constants(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user