diff options
author | Xavier Noria <fxn@hashref.com> | 2010-02-11 00:03:55 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-02-11 00:03:55 +0100 |
commit | 6a395c68d20bf72db826c53d5f44b3bde5069699 (patch) | |
tree | d48fe08049f83c991d69c6a4498db2c5c108c17d /railties/guides/source/active_support_core_extensions.textile | |
parent | 783ce11708a63a6a015dd07e6ab0e79a5f98af8f (diff) | |
download | rails-6a395c68d20bf72db826c53d5f44b3bde5069699.tar.gz rails-6a395c68d20bf72db826c53d5f44b3bde5069699.tar.bz2 rails-6a395c68d20bf72db826c53d5f44b3bde5069699.zip |
AS guide: documents Object#subclasses_of
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-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 2d05e66307..da22b4113d 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -323,6 +323,40 @@ TIP: Since +with_options+ forwards calls to its receiver they can be nested. Eac NOTE: Defined in +active_support/core_ext/object/with_options.rb+. +h5. +subclasses_of+ + +The method +subclasses_of+ receives an arbitrary number of class objects and returns all their anonymous or 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+ FIX 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. |