Reputation: 4870
Let's say I have an array with multiple hashes
[#<Campaign id: 144> , #<Campaign id: 146>]
I've stripped out the other fields for simplicities sake, but the object does have many fields. What I want to end up with is an array of unique hash IDs, for example: [144, 146]
. Of course there are many ways to do this naively, but I want to know what the best way to do it is. I'm struggling to find a function that was built for this purpose.
Upvotes: 2
Views: 3583
Reputation: 270637
What you have there appears not to be an array of hashes, but rather an array of some other type of object (Campaign
). You should be able to get this via the object_id
property and .map()
:
your_array.map(&:object_id)
Upvotes: 4