class RuboCop::Cop::Style::StringHashKeys

This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

@example

# bad
{ 'one' => 1, 'two' => 2, 'three' => 3 }

# good
{ one: 1, two: 2, three: 3 }

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/style/string_hash_keys.rb, line 41
def autocorrect(node)
  lambda do |corrector|
    symbol_content = node.str_content.to_sym.inspect
    corrector.replace(node.source_range, symbol_content)
  end
end
on_pair(node) click to toggle source
# File lib/rubocop/cop/style/string_hash_keys.rb, line 34
def on_pair(node)
  return unless string_hash_key?(node)
  return if receive_environments_method?(node)

  add_offense(node.key)
end