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
  • 426,620
  • 70
  • 833
  • 800
Mike Housky
  • 3,959
  • 1
  • 17
  • 31

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
  • 25,495
  • 2
  • 36
  • 52
eugen
  • 8,916
  • 11
  • 57
  • 65
  • 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