Each vs map Let the following each: users_ids = [] users.each { |user| users_ids << user.id } It can be simplified to: users_ids = users.map { |user| user.id } or even: users_ids = users.map &:id