class RuboCop::Cop::Lint::DuplicatedKey
This cop checks for duplicated keys in hash literals.
This cop mirrors a warning in Ruby 2.2.
@example
# bad hash = { food: 'apple', food: 'orange' }
@example
# good hash = { food: 'apple', other_food: 'orange' }
Constants
- MSG
Public Instance Methods
on_hash(node)
click to toggle source
# File lib/rubocop/cop/lint/duplicated_key.rb, line 25 def on_hash(node) keys = node.keys.select(&:recursive_basic_literal?) return unless duplicates?(keys) consecutive_duplicates(keys).each do |key| add_offense(key) end end