diff options
author | Alexey Chernenkov <laise@pisem.net> | 2013-06-05 13:05:53 +0600 |
---|---|---|
committer | Alexey Chernenkov <laise@pisem.net> | 2013-11-15 19:54:51 +0600 |
commit | 0e953c94b152abf0de1c04dba74c22f935bc85c7 (patch) | |
tree | a916e031786e90c2fc96200b573d51e879e9ffb8 /guides/source | |
parent | 81475534ed9e2e1b7bade50f1e1099975e385a46 (diff) | |
download | rails-0e953c94b152abf0de1c04dba74c22f935bc85c7.tar.gz rails-0e953c94b152abf0de1c04dba74c22f935bc85c7.tar.bz2 rails-0e953c94b152abf0de1c04dba74c22f935bc85c7.zip |
Unify `cattr_*` interface: allow to pass a block to `cattr_reader`.
Example:
class A
cattr_reader(:defr) { 'default_reader_value' }
end
A.defr # => 'default_reader_value'
Diffstat (limited to 'guides/source')
-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 |