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

  • SEARCH
  • Home
  • 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 583425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:47:29+00:00 2026-05-13T14:47:29+00:00

Possible Duplicate: What does map(&:name) mean in Ruby? What are things like survey.map(&:questions).flatten.compact called,

  • 0

Possible Duplicate:
What does map(&:name) mean in Ruby?

What are things like survey.map(&:questions).flatten.compact called, so I can find more information about them :). What problems does that &: solve, or what is it doing exactly? Is it used in other languages?

  • 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-13T14:47:29+00:00Added an answer on May 13, 2026 at 2:47 pm

    This is shorthand for:

    survey.map { |s| s.questions }.flatten.compact
    

    It’s the Symbol#to_proc method. It used to be a part of Rails’ ActiveSupport, but has since been added to Ruby syntax.

    As far as performance goes, I wrote a quick benchmark script to get an idea of performance effect in both 1.8 and 1.9.

    require 'benchmark'
    
    many = 500
    a = (1..10000).to_a
    
    Benchmark.bm do |x|
      x.report('block once') { a.map { |n| n.to_s } }
      x.report('to_proc once') { a.map(&:to_s) }
      x.report('block many') { many.times { a.map { |n| n.to_s } } }
      x.report('to_proc many') { many.times { a.map(&:to_s) } }
    end
    

    First off, before giving you the results – if you weren’t already sure that Ruby 1.9 was a huge speed improvement in general, prepare to be blown away.

    Ruby 1.8 results:

                    user        system      total       real
    block once      0.020000    0.000000    0.020000    (  0.016781)
    to_proc once    0.010000    0.000000    0.010000    (  0.013881)
    block many      6.680000    1.100000    7.780000    (  7.780532)
    to_proc many    7.370000    0.540000    7.910000    (  7.902935)
    

    Ruby 1.9 results:

                    user        system      total       real
    block once      0.010000    0.000000    0.010000    (  0.011433)
    to_proc once    0.000000    0.000000    0.000000    (  0.004929)
    block many      4.060000    0.000000    4.060000    (  4.057013)
    to_proc many    2.810000    0.000000    2.810000    (  2.810312)
    

    First off: Wow. Ruby 1.9 is fast. But the more relevant conclusions we draw here are interesting:

    • In both cases, for only one run, to_proc is clearly faster. In 1.8 on the many-times run, it’s tad slower. This seems to indicate that the only real performance bottleneck is creating all those Proc objects.
    • In Ruby 1.9, however, the to_proc method is clearly much faster than blocks, no matter how many times you do it. In this case, you not only get cleaner code, but improved performance, as well.

    In the end, no matter which version you’re using, to_proc is clearly not enough of a performance issue to be worth not using – in fact, it sometimes speeds things up!

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

Sidebar

Ask A Question

Stats

  • Questions 482k
  • Answers 482k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would suggest a different approach to this. Having different… May 16, 2026 at 6:38 am
  • Editorial Team
    Editorial Team added an answer I use a combination of Cucumber + Shoulda, but what… May 16, 2026 at 6:38 am
  • Editorial Team
    Editorial Team added an answer db1 = dbConnections.dbConnn Here you assign the class dbConn to… May 16, 2026 at 6:38 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.