Permalink
Browse files

more documentation for class_inheritable_*

  • Loading branch information...
1 parent 0a86cb5 commit 06e4c48815d810fef516241e1978ea0818501e03 Neeraj Singh committed with fxn Aug 5, 2010
Showing with 22 additions and 0 deletions.
  1. +22 −0 activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
View
22 activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
@@ -5,13 +5,35 @@
module ClassInheritableAttributes # :nodoc:
end
+# It is recommend to use <tt>class_attribute</tt> over methods defined in this file. Please
+# refer to documentation for <tt>class_attribute</tt> for more infor. Officially it is not
+# deprected but <tt>class_attribute</tt> is faster.
+#
# Allows attributes to be shared within an inheritance hierarchy. Each descendant gets a copy of
# their parents' attributes, instead of just a pointer to the same. This means that the child can add elements
# to, for example, an array without those additions being shared with either their parent, siblings, or
# children. This is unlike the regular class-level attributes that are shared across the entire hierarchy.
#
# The copies of inheritable parent attributes are added to subclasses when they are created, via the
# +inherited+ hook.
+#
+# class Person
+# class_inheritable_accessor :hair_colors
+# end
+#
+# Person.hair_colors = [:brown, :black, :blonde, :red]
+# Person.hair_colors #=> [:brown, :black, :blonde, :red]
+# Person.new.hair_colors #=> [:brown, :black, :blonde, :red]
+#
+# To opt out of the instance writer method, pass :instance_writer => false.
+# To opt out of the instance reader method, pass :instance_reader => false.
+#
+# class Person
+# cattr_accessor :hair_colors :instance_writer => false, :instance_reader => false
+# end
+#
+# Person.new.hair_colors = [:brown] # => NoMethodError
+# Person.new.hair_colors # => NoMethodError
class Class # :nodoc:
def class_inheritable_reader(*syms)
options = syms.extract_options!

0 comments on commit 06e4c48

Please sign in to comment.