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 } }
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 } }
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.