Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8555

Show
Ignore:
Timestamp:
01/04/08 03:25:20 (9 months ago)
Author:
bitsweat
Message:

Ruby 1.9: Module#local_constants can now just use constants(false). Closes #10648 [Xavier Noria]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/core_ext/module/introspection.rb

    r8482 r8555  
    66    parent_name.empty? ? Object : parent_name.constantize 
    77  end 
    8    
     8 
    99  # Return all the parents of this module, ordered from nested outwards. The 
    1010  # receiver is not contained within the result. 
     
    1919    parents 
    2020  end 
    21    
    22   # Return the constants that have been defined locally by this object and not 
    23   # in an ancestor. This method may miss some constants if their definition in 
    24   # the ancestor is identical to their definition in the receiver. 
    25   def local_constants 
    26     inherited = {} 
    27     ancestors.each do |anc| 
    28       next if anc == self 
    29       anc.constants.each { |const| inherited[const] = anc.const_get(const) } 
     21 
     22  if RUBY_VERSION < '1.9' 
     23    # Return the constants that have been defined locally by this object and 
     24    # not in an ancestor. This method is exact if running under Ruby 1.9. In 
     25    # previous versions it may miss some constants if their definition in some 
     26    # ancestor is identical to their definition in the receiver. 
     27    def local_constants 
     28      inherited = {} 
     29 
     30      ancestors.each do |anc| 
     31        next if anc == self 
     32        anc.constants.each { |const| inherited[const] = anc.const_get(const) } 
     33      end 
     34 
     35      constants.select do |const| 
     36        !inherited.key?(const) || inherited[const].object_id != const_get(const).object_id 
     37      end 
    3038    end 
    31     constants.select do |const| 
    32       ! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id 
     39  else 
     40    def local_constants #:nodoc: 
     41      constants(false) 
    3342    end 
    3443  end