1

I have this code, and rubocop tell me "Rubocop Lint/Void: Literal used in void context". How can I modify this problem and fix this message. Thanks.

e.messages.map.each { |key, message| { field: key, message: message } }
yueye
  • 11
  • 4

1 Answers1

3

I think the problem is with using map and each altogether. Yes, you can use both but there is no need to use both here. Either you should use:

e.messages.each { |key, message| { field: key, message: message } }

Or you should use:

e.messages.map { |key, message| { field: key, message: message } }

The basic difference is that each returns the original array whereas map returns the resultant array.

Here is the difference between map & each explained very well.

NN796
  • 1,247
  • 11
  • 31