Skip to content

Conversation

@sherwinyu
Copy link
Contributor

Documentation fix clarifying that #filter needs to return an array. Previously it said that "And it's also safe to mutate keys argument by doing keys.delete(:author) in case you want to avoid creating two extra arrays." -- I had taken this to mean that I could just modify the original keys argument and the return value of filters would be discarded, which is wrong. I added clarification that if you do modify the original array, you have to return it!

This lead to a tricky bug for me, where I wanted to filter out keys that had undefined values:

def filter(keys)
  keys.reject!{ |key| object[key].nil?}
end

I was using the in-place Array#reject! because I thought the original array argument would be used. This was tricky because while reject! normally returns the array, when nothing was rejected, it returns nil, causing this to to fail.

spastorino added a commit that referenced this pull request Dec 27, 2013
Update README documentation on Serializer#filter
@spastorino spastorino merged commit e6bb000 into rails-api:master Dec 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants