From 1ff35304885d86800d802748a053e0f4bef2ac91 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Mon, 7 May 2012 19:04:27 -0500 Subject: better docs for cattr_accessor and cattr_writer --- .../active_support/core_ext/class/attribute_accessors.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'activesupport') 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) -- cgit v1.2.3