Proc syntax question

Hi,

I’ve been passing methods as into enumerables and will usually do something like:

array.map { |int| int.length }

or

array.sort_by { |word| word.length }

However Rubocop keeps suggesting that I use:

array.map(&:length)
array.sort_by(&:length)

I understand that the & is needed to pass and a block into a functions by converting it to a proc e.g.,:

def test(val, &proc1) { |n| n ** 2 }
# do stuff
end

However it’s a little lost on me as to why I need to reference a symbol with the method name. In the case of ‘&:length’, what is the reason that I need to convert ‘:length’ (&:length) into a proc instead of ‘length’ (&length)? It’s a bit confusing since length isn’t a block but a method.

Thanks in advance,
Ryan