diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2010-01-26 15:38:49 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-01-26 15:38:49 -0800 |
commit | aef76d1e7120a16e0cace1ca89c327c70cbaddf3 (patch) | |
tree | f08da969bc8289aed4d0d9ed0c95c637d6ae8f74 /activesupport/lib/active_support | |
parent | 458b6a7fc905a23643fc0d26146e6bf230c9c472 (diff) | |
parent | 3c6891593d84b83c70441b4c953080481bdcc4bf (diff) | |
download | rails-aef76d1e7120a16e0cace1ca89c327c70cbaddf3.tar.gz rails-aef76d1e7120a16e0cace1ca89c327c70cbaddf3.tar.bz2 rails-aef76d1e7120a16e0cace1ca89c327c70cbaddf3.zip |
Merge remote branch 'fxn/master'
Diffstat (limited to 'activesupport/lib/active_support')
4 files changed, 0 insertions, 122 deletions
diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb index 44ad6c8c08..62df7d8b82 100644 --- a/activesupport/lib/active_support/core_ext/class.rb +++ b/activesupport/lib/active_support/core_ext/class.rb @@ -1,4 +1,3 @@ require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/inheritable_attributes' -require 'active_support/core_ext/class/removal' require 'active_support/core_ext/class/delegating_attributes' diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb deleted file mode 100644 index 652be4ed78..0000000000 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'active_support/core_ext/object/extending' -require 'active_support/core_ext/module/introspection' - -class Class #:nodoc: - - def reachable? - eval("defined?(::#{self}) && ::#{self}.equal?(self)") - end - - # Unassociates the class with its subclasses and removes the subclasses - # themselves. - # - # Integer.remove_subclasses # => [Bignum, Fixnum] - # Fixnum # => NameError: uninitialized constant Fixnum - def remove_subclasses - Object.remove_subclasses_of(self) - end - - # Returns an array with the names of the subclasses of +self+ as strings. - # - # Integer.subclasses # => ["Bignum", "Fixnum"] - def subclasses - Object.subclasses_of(self).map { |o| o.to_s } - end - - # Removes the classes in +klasses+ from their parent module. - # - # Ordinary classes belong to some module via a constant. This method computes - # that constant name from the class name and removes it from the module it - # belongs to. - # - # Object.remove_class(Integer) # => [Integer] - # Integer # => NameError: uninitialized constant Integer - # - # Take into account that in general the class object could be still stored - # somewhere else. - # - # i = Integer # => Integer - # Object.remove_class(Integer) # => [Integer] - # Integer # => NameError: uninitialized constant Integer - # i.subclasses # => ["Bignum", "Fixnum"] - # Fixnum.superclass # => Integer - def remove_class(*klasses) - klasses.flatten.each do |klass| - # Skip this class if there is nothing bound to this name - next unless defined?(klass.name) - - basename = klass.to_s.split("::").last - parent = klass.parent - - # Skip this class if it does not match the current one bound to this name - next unless parent.const_defined?(basename) && klass = parent.const_get(basename) - - parent.instance_eval { remove_const basename } unless parent == klass - end - end -end diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 04e8f06b3d..08e07a5b24 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -4,7 +4,6 @@ require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/conversions' -require 'active_support/core_ext/object/extending' require 'active_support/core_ext/object/instance_variables' require 'active_support/core_ext/object/metaclass' require 'active_support/core_ext/object/misc' diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb deleted file mode 100644 index b8b6970382..0000000000 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'active_support/core_ext/class/removal' -require 'active_support/core_ext/object/blank' - -class Class - # Rubinius - if defined?(Class.__subclasses__) - def descendents - subclasses = [] - __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents } - subclasses - end - else - # MRI - begin - ObjectSpace.each_object(Class.new) {} - - def descendents - subclasses = [] - ObjectSpace.each_object(class << self; self; end) do |k| - subclasses << k unless k == self - end - subclasses - end - # JRuby - rescue StandardError - def descendents - subclasses = [] - ObjectSpace.each_object(Class) do |k| - subclasses << k if k < self - end - subclasses.uniq! - subclasses - end - end - end -end - -class Object - def remove_subclasses_of(*superclasses) #:nodoc: - Class.remove_class(*subclasses_of(*superclasses)) - end - - # Exclude this class unless it's a subclass of our supers and is defined. - # We check defined? in case we find a removed class that has yet to be - # garbage collected. This also fails for anonymous classes -- please - # submit a patch if you have a workaround. - def subclasses_of(*superclasses) #:nodoc: - subclasses = [] - superclasses.each do |klass| - subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?} - end - subclasses - end - - def extended_by #:nodoc: - ancestors = class << self; ancestors end - ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] - end - - def extend_with_included_modules_from(object) #:nodoc: - object.extended_by.each { |mod| extend mod } - end -end |