class RuboCop::Cop::Lint::SharedMutableDefault

Hash.new { |h, k| h = {} }
Hash.new { |h, k| h = [] }
# good - using a block will create a new object for each key
h.default_proc = ->(h, k) { {} }
h.default_proc = ->(h, k) { [] }
h = Hash.new
# good - using a proc will create a new object for each key
Hash.new({}.freeze)
Hash.new([].freeze)
# good - frozen solution will raise an error when mutation attempted
Hash.new { [] }
Hash.new { {} }
Hash.new { Hash.new }
Hash.new { Array.new }
# okay – beware this will discard mutations and only remember assignments
h # => {:a => [1, 2], :b => [1, 2]}
<< 2<br>h << 1
h.default = []
h = Hash.new
# without disabling the cop, you can set the default explicitly.
# okay – In rare cases that intentionally have this behavior,
Hash.new(Hash.new)
Hash.new(Array.new)
Hash.new({})
Hash.new([])
# bad
@example
other keys that have not been explicitly assigned to.
calling ‘hash << ’bar’‘ will also change the value of all
For example, when the `Hash` was created with an `Array` as the argument,
across all keys, causing unexpected behavior when modifying it.
Creating a `Hash` in such a way will share the default value
Checks for `Hash` creation with a mutable default value.

def on_send(node)

def on_send(node)
  return unless hash_initialized_with_mutable_shared_object?(node)
  add_offense(node)
end