diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2011-01-18 13:34:12 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-01-18 15:02:41 +0800 |
commit | cc446eee99b9e480637ea8792349068d2c98fc85 (patch) | |
tree | b8ac3fca5f3395f5049290caff6d57043aa970a1 /activesupport | |
parent | 199d1abeb2908a48b161f7ae3be6a0b078619a40 (diff) | |
download | rails-cc446eee99b9e480637ea8792349068d2c98fc85.tar.gz rails-cc446eee99b9e480637ea8792349068d2c98fc85.tar.bz2 rails-cc446eee99b9e480637ea8792349068d2c98fc85.zip |
Class.__subclasses__ was removed from Rubinius.
https://github.com/evanphx/rubinius/issues/issue/11
https://github.com/evanphx/rubinius/commit/2fccbb5dad5cb3f5414d635547290538cfc0a2d4
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/class/subclasses.rb | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb index 3e5d1a2a42..46e9daaa8f 100644 --- a/activesupport/lib/active_support/core_ext/class/subclasses.rb +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -2,49 +2,35 @@ require 'active_support/core_ext/module/anonymous' require 'active_support/core_ext/module/reachable' class Class #:nodoc: - # Rubinius - if defined?(Class.__subclasses__) - alias :subclasses :__subclasses__ + begin + ObjectSpace.each_object(Class.new) {} def descendants descendants = [] - __subclasses__.each do |k| - descendants << k - descendants.concat k.descendants + ObjectSpace.each_object(class << self; self; end) do |k| + descendants.unshift k unless k == self end descendants end - else # MRI - begin - ObjectSpace.each_object(Class.new) {} - - def descendants - descendants = [] - ObjectSpace.each_object(class << self; self; end) do |k| - descendants.unshift k unless k == self - end - descendants - end - rescue StandardError # JRuby - def descendants - descendants = [] - ObjectSpace.each_object(Class) do |k| - descendants.unshift k if k < self - end - descendants.uniq! - descendants + rescue StandardError # JRuby + def descendants + descendants = [] + ObjectSpace.each_object(Class) do |k| + descendants.unshift k if k < self end + descendants.uniq! + descendants end + end - # Returns an array with the direct children of +self+. - # - # Integer.subclasses # => [Bignum, Fixnum] - def subclasses - subclasses, chain = [], descendants - chain.each do |k| - subclasses << k unless chain.any? { |c| c > k } - end - subclasses + # Returns an array with the direct children of +self+. + # + # Integer.subclasses # => [Bignum, Fixnum] + def subclasses + subclasses, chain = [], descendants + chain.each do |k| + subclasses << k unless chain.any? { |c| c > k } end + subclasses end end |