diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-07 19:37:00 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-07 19:37:00 -0500 |
commit | 2805c28e3e9a7386fe144754a9b664c424add2b3 (patch) | |
tree | 455060da40418ff784dc18fef50e0e4f153ac015 /activesupport | |
parent | 1ff35304885d86800d802748a053e0f4bef2ac91 (diff) | |
download | rails-2805c28e3e9a7386fe144754a9b664c424add2b3.tar.gz rails-2805c28e3e9a7386fe144754a9b664c424add2b3.tar.bz2 rails-2805c28e3e9a7386fe144754a9b664c424add2b3.zip |
added docs to cattr_reader
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/class/attribute_accessors.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb index 4461cd6608..8b41b10c32 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -34,6 +34,33 @@ require 'active_support/core_ext/array/extract_options' # Person.new.hair_colors = [:brown] # => NoMethodError # Person.new.hair_colors # => NoMethodError class Class + # Defines a class attribute if it's not defined and creates a reader method that + # returns the attribute value. + # + # class Person + # cattr_reader :hair_colors + # end + # + # Person.class_variable_set("@@hair_colors", [:brown, :black]) + # Person.hair_colors # => [:brown, :black] + # Person.new.hair_colors # => [:brown, :black] + # + # The attribute name must be any word character starting with a letter or underscore + # and without spaces. + # + # class Person + # cattr_reader :"1_Badname " + # end + # # => NameError: invalid attribute name + # + # If you want to opt out the instance writer method, pass <tt>instance_reader: false</tt> + # or <tt>instance_accessor: false</tt>. + # + # class Person + # cattr_reader :hair_colors, instance_reader: false + # end + # + # Person.new.hair_colors # => NoMethodError def cattr_reader(*syms) options = syms.extract_options! syms.each do |sym| |