20

In Ruby, you can apply a map function to every element of an array:

@files.map { |f| f.read) }

For which there is the syntactic sugar:

@files.map(&:read)

Is there any equivalent for

@files.map { |f| read(f) } 

That is terser, similar to the above?

user2398029
  • 6,699
  • 8
  • 48
  • 80

1 Answers1

27

You can do this

@files.map(&method(:read))

But be aware though about performance.

Community
  • 1
  • 1
oldergod
  • 15,033
  • 7
  • 62
  • 88