0

This is from a solution I saw at a competitive programming site:

    gets.split.map &:to_i

The &:to_i phrase seems to be equivalent to {|s| s.to_i}, but I can't find anything about that syntax at ruby-doc.org, or a match for "&:" [ruby] here. (I don't know what to call it for an English language search, either.)

If it matters, that site is using Ruby 3.0.1.

mu is too short
  • 413,090
  • 67
  • 810
  • 771
Mike Housky
  • 3,822
  • 1
  • 16
  • 29

1 Answers1

0

It's an example of Symbol#to_proc - see https://www.brianstorti.com/understanding-ruby-idiom-map-with-symbol/ for a more detailed explanation, or the ruby API documentation

engineersmnky
  • 22,010
  • 2
  • 32
  • 47
eugen
  • 8,608
  • 11
  • 57
  • 64
  • Thank you! The API doc link is what I tried to find, but I still don't see how I'd have found it on my own if I didn't already know the answer to my question. – Mike Housky Mar 23 '22 at 10:12