Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4032604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:44:32+00:00 2026-05-20T11:44:32+00:00

I won’t repeat my question here, but is there are more efficient way to

  • 0

I won’t repeat my question here, but is there are more efficient way to write this?

  def recruits_names
    names = []
    for r in self.referrals do
      names << r.display_name
    end

    return names
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:44:33+00:00Added an answer on May 20, 2026 at 11:44 am

    Use the map method:

    Returns a new array with the results of running block once for every element in enum.

    def recruits_names
      self.referrals.map { |r| r.display_name }
    end
    

    [Update] As indicated by Staelen in the comments, this example can be shortened even further to:

    def recruits_names
      self.referrals.map(&:display_name)
    end
    

    For the curious, this is because & calls to_proc on the object following it (when used in a method call), and Symbol implements to_proc to return a Proc that executes the method indicated by the symbol on each value yielded to the block (see the documentation).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this won't be a popular question, because a lot of web designers
Any ideas why this won't validate here: http://validator.w3.org/#validate_by_input It seems the form input tags
I have the following code that won't compile and although there is a way
Won't the union in this question cause UB when used as this: union Data
i won't to download multi files at this same time using c#, but i
This just won't work. The problem is that I do not know enough to
I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads);
Why won't this simple subtraction work? int MyPageNumber = Convert.ToInt32(cboPageNumber.SelectedItem); MyPageNumber += (MyPageNumber -
SVN won't download newly added files but will update existing. Developer B adds 3
Why won't this xml schema validate ? Visual studio says that the simpleContent tag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.