diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-15 07:13:43 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-11-15 07:13:43 -0800 |
commit | 72551c29f26f757af72b0fefd689244fb6366c74 (patch) | |
tree | f776d3f501a1efa8b9e71c250295a95b457a3709 /guides | |
parent | e7c90e646b48b7995401e3db963431664f045b00 (diff) | |
parent | 0e953c94b152abf0de1c04dba74c22f935bc85c7 (diff) | |
download | rails-72551c29f26f757af72b0fefd689244fb6366c74.tar.gz rails-72551c29f26f757af72b0fefd689244fb6366c74.tar.bz2 rails-72551c29f26f757af72b0fefd689244fb6366c74.zip |
Merge pull request #10848 from 907th/add_block_to_cattr_reader
Fix #10847: allow to pass a block to `cattr_reader`.
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 648036fb3f..84a169b3b9 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -1093,6 +1093,15 @@ end we can access `field_error_proc` in views. +Also, you can pass a block to `cattr_*` to set up the attribute with a default value: + +```ruby +class MysqlAdapter < AbstractAdapter + # Generates class methods to access @@emulate_booleans with default value of true. + cattr_accessor(:emulate_booleans) { true } +end +``` + The generation of the reader instance method can be prevented by setting `:instance_reader` to `false` and the generation of the writer instance method can be prevented by setting `:instance_writer` to `false`. Generation of both methods can be prevented by setting `:instance_accessor` to `false`. In all cases, the value must be exactly `false` and not any false value. ```ruby |