Ticket #10822: document_cattr.diff
| File document_cattr.diff, 2.2 kB (added by chuyeow, 9 months ago) |
|---|
-
activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
old new 1 1 # Extends the class object with class and instance accessors for class attributes, 2 2 # just like the native attr* accessors for instance attributes. 3 class Class # :nodoc: 3 class Class 4 # Creates class attributes and corresponding class and instance methods that return 5 # the value of each class attribute. 6 # 7 # ==== Example 8 # class Foo 9 # cattr_reader :size 10 # end 11 # 12 # is equivalent to: 13 # 14 # class Foo 15 # def self.size 16 # @@size 17 # end 18 # def size 19 # @@size 20 # end 21 # end 22 # 23 # The <code>@@size</code> class variable is set to <code>nil</code> (unless it is already defined). 4 24 def cattr_reader(*syms) 5 25 syms.flatten.each do |sym| 6 26 next if sym.is_a?(Hash) … … 20 40 end 21 41 end 22 42 43 # Creates class attributes and corresponding class and instance methods that allow 44 # assignment to each class attribute. 45 # 46 # ==== Options 47 # * <tt>:instance_writer</tt> - Set to false if you don't want the instance method to be defined. Defaults to true. 48 # 49 # ==== Example 50 # class Foo 51 # cattr_writer :size 52 # end 53 # 54 # is equivalent to: 55 # 56 # class Foo 57 # def self.size=(val) 58 # @@size = val 59 # end 60 # def size=(val) 61 # @@size = val 62 # end 63 # end 64 # 65 # The <code>@@size</code> class variable is set to <code>nil</code> (unless it is already defined). 23 66 def cattr_writer(*syms) 24 67 options = syms.extract_options! 25 68 syms.flatten.each do |sym| … … 41 84 end 42 85 end 43 86 87 # Creates class attributes and corresponding class and instance accessor methods for 88 # reading and writing each class attribute. 89 # 90 # This is equivalent to calling <code>cattr_reader</code> and <code>cattr_accessor</code> 91 # with the same arguments. 44 92 def cattr_accessor(*syms) 45 93 cattr_reader(*syms) 46 94 cattr_writer(*syms)