Mega Code Archive

 
Categories / Ruby / String
 

Rescue a Attempting-to-modify exception

str = "This is a test. " str.freeze begin   str << " Don't be alarmed."   # Attempting to modify rescue => err   puts "#{err.class} #{err}" end # Output: #   TypeError: can't modify frozen string