diff options
author | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-07 19:04:27 -0500 |
---|---|---|
committer | Francesco Rodriguez <lrodriguezsanc@gmail.com> | 2012-05-07 19:04:27 -0500 |
commit | 1ff35304885d86800d802748a053e0f4bef2ac91 (patch) | |
tree | 3f0e4d73ef06343315d6a3c45686717ada2e70a1 /activesupport/lib | |
parent | 2fb6d12ad3a03c1d9b310fc6a01150f1af2af73b (diff) | |
download | rails-1ff35304885d86800d802748a053e0f4bef2ac91.tar.gz rails-1ff35304885d86800d802748a053e0f4bef2ac91.tar.bz2 rails-1ff35304885d86800d802748a053e0f4bef2ac91.zip |
better docs for cattr_accessor and cattr_writer
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/class/attribute_accessors.rb | 16 |
1 files changed, 14 insertions, 2 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 7d85fd512c..4461cd6608 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -87,10 +87,12 @@ class Class # # Person.new.hair_colors = [:blonde, :red] # => NoMethodError # - # Also, you can pass a block to set up the variable with a default value. + # Also, you can pass a block to set up the attribute with a default value. # # class Person - # cattr_writer(:hair_colors) {[:brown, :black, :blonde, :red]} + # cattr_writer :hair_colors do + # [:brown, :black, :blonde, :red] + # end # end # # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red] @@ -157,6 +159,16 @@ class Class # # Person.new.hair_colors = [:brown] # => NoMethodError # Person.new.hair_colors # => NoMethodError + # + # Also you can pass a block to set up the attribute with a default value. + # + # class Person + # cattr_accessor :hair_colors do + # [:brown, :black, :blonde, :red] + # end + # end + # + # Person.class_variable_get("@@hair_colors") #=> [:brown, :black, :blonde, :red] def cattr_accessor(*syms, &blk) cattr_reader(*syms) cattr_writer(*syms, &blk) |