29

I wrote this code:

my.objects.map { |object| object.key }

My rubocop said:

Pass &:key as an argument to map instead of a block.

Is there a short way to do the same thing?

s-cho-m
  • 967
  • 2
  • 13
  • 28

1 Answers1

54

Pass &:key as an argument to map instead of a block

means:

my.objects.map(&:key)
shivam
  • 16,048
  • 3
  • 56
  • 71
  • 4
    For people having any confusion, you can pass 'transformation function' like `to_i` or `to_s` instead of key. That is to say, it'll look something like below. `my.objects.map(&:to_i)` – darkdefender27 Jul 11 '18 at 05:59