diff options
author | Xavier Noria <fxn@hashref.com> | 2010-01-17 00:07:08 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-01-17 00:07:08 +0100 |
commit | 0ec76099e06ac342261473fcaa88db4f58a2a8b3 (patch) | |
tree | 8b85c81122eec217a2622241a5884ee7fd1bce85 /railties/guides | |
parent | 844b8e77970c52209f8677a9e498bdb1f7170ac1 (diff) | |
download | rails-0ec76099e06ac342261473fcaa88db4f58a2a8b3.tar.gz rails-0ec76099e06ac342261473fcaa88db4f58a2a8b3.tar.bz2 rails-0ec76099e06ac342261473fcaa88db4f58a2a8b3.zip |
AS guide: documents Object#subclasses_of
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 32d9d4c413..ee1c83673c 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -329,6 +329,40 @@ h5. +remove_subclasses_of+ The method +remove_subclasses_of+ receives an arbitrary number of class objects and removes their subclasses. It is a wrapper of +Class#remove_class+ explained with more details in "Class Removal FIX THIS LINK":FIXME. +h5. +subclasses_of+ + +The method +subclasses_of+ receives an arbitrary number of class objects and returns all their reachable descendants as a single array: + +<ruby> +class C; end +subclasses_of(C) # => [] + +subclasses_of(Integer) # => [Bignum, Fixnum] + +module M + class A; end + class B1 < A; end + class B2 < A; end +end + +module N + class C < M::B1; end +end + +subclasses_of(M::A) # => [N::C, M::B2, M::B1] +</ruby> + +The order in which these classes are returned is unspecified. The returned collection may have duplicates: + +<ruby> +subclasses_of(Numeric, Integer) +# => [Bignum, Float, Fixnum, Integer, Date::Infinity, Rational, BigDecimal, Bignum, Fixnum] +</ruby> + +See also +Class#subclasses+ in "Extensions to +Class+ FIXME THIS LINK":FIXME. + +NOTE: Defined in +active_support/core_ext/object/extending.rb+. + h4. Instance Variables Active Support provides several methods to ease access to instance variables. |