Switch from class_inheritable_accessor to class_attribute #9

Merged
merged 1 commit into from Jul 23, 2011

2 participants

@brynary

class_inheritable_accessor is deprecated in Rails 3.1. class_attribute has slightly different semantics, but this change should be functionality neutral since it appears there's only one place where the attachment_names Set is modified.

@brynary brynary Switch from class_inheritable_accessor to class_attribute
* class_inheritable_accessor is deprecated in Rails 3.1
7e6a49c
@bkeepers bkeepers commented on the diff Jul 23, 2011
lib/joint/class_methods.rb
@@ -8,7 +8,7 @@ module Joint
options.symbolize_keys!
name = name.to_sym
- self.attachment_names << name
+ self.attachment_names = attachment_names.dup.add(name)

What's the advantage of duping here? Do we need a test for it?

@brynary
brynary added a note Jul 23, 2011

Duping is required so we don't mutate the Set object. This is required, and if you remove the dup two tests will fail so it seems to be well covered.

Docs on class_attribute explain this a bit: api.rubyonrails.org/classes/Class.html#method-i-class_attribute

Specifically: "However, you need to be aware when using class_attribute with mutable structures as Array or Hash. In such cases, you don’t want to do changes in places but use setters:"

awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bkeepers bkeepers merged commit f7a0609 into jnunemaker:master Jul 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment