aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_overview.textile
diff options
context:
space:
mode:
authorMurray Steele <muz@h-lame.com>2009-05-31 22:14:58 +0100
committerMurray Steele <muz@h-lame.com>2009-05-31 22:14:58 +0100
commita6584bba749fe5ba3dc26117a09fc9db81a3f268 (patch)
treef83dcf3d7dd997a61b96057b84acca0c68c73cef /railties/guides/source/active_support_overview.textile
parentb418f8c6a217a9041b1c2cfc034a6aebbf633682 (diff)
parentf60b732940e4785c522398dff2a409ac616351ec (diff)
downloadrails-a6584bba749fe5ba3dc26117a09fc9db81a3f268.tar.gz
rails-a6584bba749fe5ba3dc26117a09fc9db81a3f268.tar.bz2
rails-a6584bba749fe5ba3dc26117a09fc9db81a3f268.zip
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'railties/guides/source/active_support_overview.textile')
-rw-r--r--railties/guides/source/active_support_overview.textile46
1 files changed, 44 insertions, 2 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index 7f72ff5186..0d9753cb84 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/railties/guides/source/active_support_overview.textile
@@ -106,9 +106,9 @@ end
If for whatever reason an application loads the definition of a mailer class and after that sets +ActionMailer::Base.delivery_method+, the mailer class will still see the new value. In addition, the mailer class is able to change the +delivery_method+ without affecting the value in the parent using its own inherited class attribute writer.
-h4. Descendants
+h4. Subclasses
-The method +Class#subclasses+ returns the names of all subclasses of a given class as an array of strings. That comprises not only direct subclasses, but all descendants down the hierarchy:
+The +subclasses+ method returns the names of all subclasses of a given class as an array of strings. That comprises not only direct subclasses, but all descendants down the hierarchy:
<ruby>
class C; end
@@ -133,6 +133,48 @@ The order in which these class names are returned is unspecified.
See also +Object#subclasses_of+ in "Extensions to All Objects FIX THIS LINK":FIXME.
+h4. Class Removal
+
+Roughly speaking, the +remove_class+ method removes the class objects passed as arguments:
+
+<ruby>
+Class.remove_class(Hash, Dir) # => [Hash, Dir]
+Hash # => NameError: uninitialized constant Hash
+Dir # => NameError: uninitialized constant Dir
+</ruby>
+
+More specifically, +remove_class+ attempts to remove constants with the same name as the passed class objects from their parent modules. So technically this method does not guarantee the class objects themselves are not indeed valid and still alive somewhere:
+
+<ruby>
+module M
+ class A; end
+ class B < A; end
+end
+
+A2 = M::A
+
+M::A.object_id # => 13053950
+Class.remove_class(M::A)
+
+M::B.superclass.object_id # => 13053950 (same object as before)
+A2.name # => "M::A" (name is hard-coded in object)
+</ruby>
+
+WARNING: Removing fundamental classes like +String+ can result in really funky behaviour.
+
+The method +remove_subclasses+ provides a shortcut for removing all descendants of a given class, where "removing" has the meaning explained above:
+
+<ruby>
+class A; end
+class B1 < A; end
+class B2 < A; end
+class C < A; end
+
+A.subclasses # => ["C", "B2", "B1"]
+A.remove_subclasses
+A.subclasses # => []
+C # => NameError: uninitialized constant C
+</ruby>
h3. Extensions to +NilClass+