method
class_inheritable_accessor
![Some documentation Importance_1](https://d2vfyqvduarcvs.cloudfront.net/images/importance_1.png?1349367920)
Register or
log in
to add new notes.
jesseclark -
August 19, 2009 - (>= v2.1.0)
Ramon -
December 14, 2012 - (>= v3.2.1)
![Default_avatar_30](https://www.gravatar.com/avatar/ad87b3869dc58ece9bc7b500067b340c?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Gotcha with class_inheritable_accessor and cloneing the attribute values
The key thing to note from post is that class_inheritable_accessor copies the value from the parent class at inherit time. So, if you are setting a default value of an array and doing something like the following you might end up with unintended results:
>> A.class_inheritable_foo << 'from a' => ["from a"] >> B.class_inheritable_foo << 'from b' => ["from a", "from b"] >> C.class_inheritable_foo << 'from c' => ["from a", "from b", "from c"]
However, if you use the form:
class << self def class_instance_foo @class_instance_processors ||= [] end end
The original values aren’t copied from the parent class when you reference the class for the first time:
>> A.class_instance_foo << 'from a' => ["from a"] >> B.class_instance_foo << 'from b' => ["from b"] >> C.class_instance_foo << 'from c' => ["from c"]
![Default_avatar_30](https://www.gravatar.com/avatar/fbd9cb107fe7c941333d6a3488691989?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Now called class_attribute in Rails 3.2.x
See github.com/novafabrica/make_exportable/pull/4