From 625cb12f21d08630577047ccf11678f886145234 Mon Sep 17 00:00:00 2001 From: Andrew France Date: Sun, 11 Mar 2012 13:28:25 +0000 Subject: attr_accessor_with_default was deprecated and removed. Deprecated in 673372152032a886ba9196c69348386834590eab and removed in 9cafc28874a681082f9f7e1e445db91f195a25ae. --- .../source/active_support_core_extensions.textile | 49 ---------------------- 1 file changed, 49 deletions(-) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 2091ce0395..5d0a3f82e8 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -509,55 +509,6 @@ end NOTE: Defined in +active_support/core_ext/module/aliasing.rb+. -h5. +attr_accessor_with_default+ - -The method +attr_accessor_with_default+ serves the same purpose as the Ruby macro +attr_accessor+ but allows you to set a default value for the attribute: - - -class Url - attr_accessor_with_default :port, 80 -end - -Url.new.port # => 80 - - -The default value can be also specified with a block, which is called in the context of the corresponding object: - - -class User - attr_accessor :name, :surname - attr_accessor_with_default(:full_name) do - [name, surname].compact.join(" ") - end -end - -u = User.new -u.name = 'Xavier' -u.surname = 'Noria' -u.full_name # => "Xavier Noria" - - -The result is not cached, the block is invoked in each call to the reader. - -You can overwrite the default with the writer: - - -url = Url.new -url.host # => 80 -url.host = 8080 -url.host # => 8080 - - -The default value is returned as long as the attribute is unset. The reader does not rely on the value of the attribute to know whether it has to return the default. It rather monitors the writer: if there's any assignment the value is no longer considered to be unset. - -Active Resource uses this macro to set a default value for the +:primary_key+ attribute: - - -attr_accessor_with_default :primary_key, 'id' - - -NOTE: Defined in +active_support/core_ext/module/attr_accessor_with_default.rb+. - h5. Internal Attributes When you are defining an attribute in a class that is meant to be subclassed, name collisions are a risk. That's remarkably important for libraries. -- cgit v1.2.3