rails/rails — Issue #3389: ActiveResource known_attributes does not remove duplicates
Author: royratcliffe
Created: 2011-10-21 13:15:06+00:00
State: open

Take the following example.

```ruby
require 'active_resource'

class Person < ActiveResource::Base
self.site = "http://localhost:3000/"
schema do
attribute 'first', :string
attribute 'last', :string
end
end

p Person.new(:first => 'Ryan', :last => 'Diagle').known_attributes
```

It outputs the following array:

["first", "last", "first", "last"]

This is because the implementation at [line 988](https://github.com/rails/rails/blob/master/activeresource/lib/active_resource/base.rb#L988) of `activeresource/lib/active_resource/base.rb` adds the instance's attribute keys to the singleton class' attribute keys. Array plus array does not remove duplicate keys. Should it not rather merge _sets_ rather than arrays?

You can work around it by sending `uniq` to the Array, i.e.

```ruby
p Person.new(:first => 'Ryan', :last => 'Diagle').known_attributes.uniq
```

Still, I wonder if it would be more natural for the implementation itself to remove duplicates, or at least it should document this 'feature!'