class RuboCop::Cop::Rails::IndexBy
- 1, 2, 3].index_by { |el| foo(el) }
# good
Hash[[1, 2, 3].collect { |el| [foo(el), el -
}]
[1, 2, 3].map { |el| [foo(el), el] }.to_h
[1, 2, 3].to_h { |el| [foo(el), el] }
[1, 2, 3].each_with_object({}) { |el, h| h = el }
# bad
@example
Rails provides the ‘index_by` method for this purpose.
an enumerable into a hash where the values are the original elements.
`map { … }.to_h`, and `Hash[map { … }]` that are transforming
Looks for uses of `each_with_object({}) { … }`,
def new_method_name
def new_method_name 'index_by' end