Ruby - Class Methods and Variables
How can you safely modify a frozen hash
h = {x: 1, y: 2}.freeze by adding a new key-value pair?h = {x: 1, y: 2}.freeze by adding a new key-value pair?h[:z] = 3 or mutating methods like merge! or update raises error.h.merge(z: 3) returns a new hash with added pair, original remains frozen.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions