Module: RuboCop::Cop::HashTransformMethod

Included in:
Style::HashTransformKeys, Style::HashTransformValues
Defined in:
lib/rubocop/cop/mixin/hash_transform_method.rb

Overview

Common functionality for Style/HashTransformKeys and Style/HashTransformValues

Defined Under Namespace

Classes: Autocorrection, Captures

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



29
30
31
32
33
34
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 29

def autocorrect(node)
  lambda do |corrector|
    correction = prepare_correction(node)
    execute_correction(corrector, node, correction)
  end
end

#on_block(node) ⇒ Object



8
9
10
11
12
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 8

def on_block(node)
  on_bad_each_with_object(node) do |*match|
    handle_possible_offense(node, match, 'each_with_object')
  end
end

#on_csend(node) ⇒ Object



23
24
25
26
27
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 23

def on_csend(node)
  on_bad_map_to_h(node) do |*match|
    handle_possible_offense(node, match, 'map {...}.to_h')
  end
end

#on_send(node) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/mixin/hash_transform_method.rb', line 14

def on_send(node)
  on_bad_hash_brackets_map(node) do |*match|
    handle_possible_offense(node, match, 'Hash[_.map {...}]')
  end
  on_bad_map_to_h(node) do |*match|
    handle_possible_offense(node, match, 'map {...}.to_h')
  end
end