Working with Frozen Hashes

I discovered a cool method today while working with a frozen hash containing a frozen array.


From the Rails API Documentation:

Returns a deep copy of hash.

 hash = { a: { b: 'b' } }
 dup  = hash.deep_dup
 dup[:a][:c] = 'c'

 hash[:a][:c] # => nil
 dup[:a][:c]  # => "c"> 

Use of this method allowed for a nice refactor:


SANITIZER = AppConfig.sanitizer.default.dup
SANITIZER[:elements] = SANITIZER[:elements].dup
SANITIZER[:elements].push "iframe"


SANITIZER = AppConfig.sanitizer.default.deep_dup
SANITIZER[:elements].push "iframe"