diff options
author | Xavier Noria <fxn@hashref.com> | 2010-02-11 23:41:16 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-02-11 23:41:16 +0100 |
commit | aa82bdf92953824fd35db4a734bf6effa8de3329 (patch) | |
tree | 257c4719fb2b37a21cdb5a5eeba62f1a5023d2b1 /activesupport/lib | |
parent | b8bb54af7ff6652327d99f6a7cf5c96a3f3f876d (diff) | |
download | rails-aa82bdf92953824fd35db4a734bf6effa8de3329.tar.gz rails-aa82bdf92953824fd35db4a734bf6effa8de3329.tar.bz2 rails-aa82bdf92953824fd35db4a734bf6effa8de3329.zip |
moves Class#reachable? to Module#reachable?, bases implementation on anonymous? and constantize, and adds test coverage
Diffstat (limited to 'activesupport/lib')
3 files changed, 14 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb index c166ce8079..bbd8f5aef6 100644 --- a/activesupport/lib/active_support/core_ext/class/subclasses.rb +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -1,4 +1,5 @@ -require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/module/reachable' class Class #:nodoc: # Returns an array with the names of the subclasses of +self+ as strings. @@ -8,10 +9,6 @@ class Class #:nodoc: Class.subclasses_of(self).map { |o| o.to_s } end - def reachable? #:nodoc: - eval("defined?(::#{self}) && ::#{self}.equal?(self)") - end - # Rubinius if defined?(Class.__subclasses__) def descendents @@ -51,7 +48,7 @@ class Class #:nodoc: def self.subclasses_of(*superclasses) #:nodoc: subclasses = [] superclasses.each do |klass| - subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?} + subclasses.concat klass.descendents.select {|k| k.anonymous? || k.reachable?} end subclasses end diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index c907445d90..07bac29a9f 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -1,6 +1,7 @@ require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/introspection' require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/module/reachable' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/attr_accessor_with_default' diff --git a/activesupport/lib/active_support/core_ext/module/reachable.rb b/activesupport/lib/active_support/core_ext/module/reachable.rb new file mode 100644 index 0000000000..443d2c3d53 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/module/reachable.rb @@ -0,0 +1,10 @@ +require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/string/inflections' + +class Module + def reachable? #:nodoc: + !anonymous? && name.constantize.equal?(self) + rescue NameError + false + end +end |