Clean way of extracting some info from an Array

I’m using the act_as_followers gem and one of the methods returns an
array of all the users that are following a specific user, example:

followers = user.all_following

What would be the clean way of extracting just the followers.id and
placing the results in an array?

I am not familiar with act_as_followers, but

followeres = user.all_following.map(&:id)

is the cleanest I can come up with.

On 24 November 2011 07:01, Hesham [email protected] wrote:

I’m using the act_as_followers gem and one of the methods returns an
array of all the users that are following a specific user, example:

followers = user.all_following

What would be the clean way of extracting just the followers.id and
placing the results in an array?

Have a look through the documentation for the Array class, map or
collect may well be useful.

Probably working through a ruby book would also be a good idea, have a
look at the Pickaxe book. You cannot use rails without a good
knowledge of Ruby.

Colin

Thank you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs