aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_overview.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-05-31 01:13:44 +0200
committerXavier Noria <fxn@hashref.com>2009-05-31 01:13:44 +0200
commita5394c93133adf3b945aa4418a0aaa4bb60342e9 (patch)
treeef93a1e4b9b6857fa7e9b0b585bac865a3aec460 /railties/guides/source/active_support_overview.textile
parent4f90eb9f1994b8f10cb854bbd0d890a816432056 (diff)
downloadrails-a5394c93133adf3b945aa4418a0aaa4bb60342e9.tar.gz
rails-a5394c93133adf3b945aa4418a0aaa4bb60342e9.tar.bz2
rails-a5394c93133adf3b945aa4418a0aaa4bb60342e9.zip
explains superclass_delegating_accessor
Diffstat (limited to 'railties/guides/source/active_support_overview.textile')
-rw-r--r--railties/guides/source/active_support_overview.textile19
1 files changed, 16 insertions, 3 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index 4f1d935593..30c896b5c5 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/railties/guides/source/active_support_overview.textile
@@ -63,6 +63,7 @@ Class variables are shared down the inheritance tree. Class instance variables a
<ruby>
module ActionController
class Base
+ # FIXME: REVISE/SIMPLIFY THIS COMMENT.
# The value of allow_forgery_protection is inherited,
# but its value in a particular class does not affect
# the value in the rest of the controllers hierarchy.
@@ -76,10 +77,7 @@ They accomplish this with class instance variables and cloning on subclassing, t
There are some variants specialised in arrays and hashes:
<ruby>
-class_inheritable_array_writer
class_inheritable_array
-
-class_inheritable_hash_writer
class_inheritable_hash
</ruby>
@@ -95,6 +93,21 @@ module ActiveRecord
end
</ruby>
+Since values are copied when a subclass is defined, if the base class changes the attribute after that, the subclass does not see the new value. That's the point.
+
+There's a related macro called +superclass_delegating_accessor+, however, that does not copy the value when the base class is subclassed. Instead, it delegates reading to the superclass as long as the attribute is not set via its own writer. For example, +ActionMailer::Base+ defined +delivery_method+ this way:
+
+<ruby>
+module ActionMailer
+ class Base
+ superclass_delegating_accessor :delivery_method
+ self.delivery_method = :smtp
+ end
+end
+</ruby>
+
+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.
+
h3. Extensions to +NilClass+
...