changed AR::Base#attributes to return a hash with indifferent access for the sake of API consistency #551

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants
@amatsuda
Member

amatsuda commented May 14, 2011

returning hwia is more consistent with other APIs, for example:

  • attributes= and update_attributes= accept both symbolized and stringified hash
  • [] accessor method accepts both Symbol and String for the attribute name

amatsuda added some commits May 14, 2011

AR::Base#attributes returns a hash with indifferent access
returning hwia is more consistent with other APIs, for example:
* attributes= and update_attributes= accept both symbolized and stringified hash
* [] accessor method accepts both Symbol and String for the attribute name
@dmitriy-kiriyenko

This comment has been minimized.

Show comment Hide comment
@dmitriy-kiriyenko

dmitriy-kiriyenko Jul 5, 2011

Contributor

+1 for that.

Contributor

dmitriy-kiriyenko commented Jul 5, 2011

+1 for that.

@steved

This comment has been minimized.

Show comment Hide comment
@steved

steved Aug 25, 2011

Contributor

I ran into this today and I would like to see it happen as well. One tweak, just create a HashWithIndifferentAccess instead of calling with_indifferent_access to (hopefully) increase the performance slightly.

Contributor

steved commented Aug 25, 2011

I ran into this today and I would like to see it happen as well. One tweak, just create a HashWithIndifferentAccess instead of calling with_indifferent_access to (hopefully) increase the performance slightly.

@jeremy

This comment has been minimized.

Show comment Hide comment
@jeremy

jeremy Oct 9, 2011

Owner

I'd like this change, too, but people use this method to get the "raw" attributes, often for serialization or caching.

This patch will change the method signature to return a different kind of class, so it breaks API compatibility.

The YAML serialization changes from a native map to a !ruby/hash:ActiveSupport::HashWithIndifferentAccess for example.

I don't think we can change this safely, though we could consider it for Rails 4.0.

Owner

jeremy commented Oct 9, 2011

I'd like this change, too, but people use this method to get the "raw" attributes, often for serialization or caching.

This patch will change the method signature to return a different kind of class, so it breaks API compatibility.

The YAML serialization changes from a native map to a !ruby/hash:ActiveSupport::HashWithIndifferentAccess for example.

I don't think we can change this safely, though we could consider it for Rails 4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment