diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2016-09-05 14:58:40 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2016-09-05 15:11:03 +0900 |
commit | 951353e4764f8ca0fbcc6e9c799eb815c612e759 (patch) | |
tree | 8c061c02529cacc2bc9abc307354125077b01926 /activesupport/lib | |
parent | 9aaf8ca7672d525e1b5d54abc07ae9d589cf4e44 (diff) | |
download | rails-951353e4764f8ca0fbcc6e9c799eb815c612e759.tar.gz rails-951353e4764f8ca0fbcc6e9c799eb815c612e759.tar.bz2 rails-951353e4764f8ca0fbcc6e9c799eb815c612e759.zip |
change `Class#descendants` to public API [ci skip]
`Class#descendants` has already been displayed in Rails guide,
so I think that may be displayed in doc.
http://guides.rubyonrails.org/active_support_core_extensions.html#descendants
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/class/subclasses.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb index 8a21c71a42..10a7c787f6 100644 --- a/activesupport/lib/active_support/core_ext/class/subclasses.rb +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -6,7 +6,20 @@ class Class # Test if this Ruby supports each_object against singleton_class ObjectSpace.each_object(Numeric.singleton_class) {} - def descendants # :nodoc: + # Returns an array with all classes that are < than its receiver. + # + # class C; end + # C.descendants # => [] + # + # class B < C; end + # C.descendants # => [B] + # + # class A < B; end + # C.descendants # => [B, A] + # + # class D < C; end + # C.descendants # => [B, A, D] + def descendants descendants = [] ObjectSpace.each_object(singleton_class) do |k| descendants.unshift k unless k == self @@ -14,7 +27,7 @@ class Class descendants end rescue StandardError # JRuby 9.0.4.0 and earlier - def descendants # :nodoc: + def descendants descendants = [] ObjectSpace.each_object(Class) do |k| descendants.unshift k if k < self |