Ruby: "runtimeerror: can't modify frozen array" issue

Example:

array = [1, 2, 3].freeze
array << 4
This error is raised when you attempt to modify an object that has been frozen.

Solution:

# Use dup to create a mutable copy or avoid freezing objects you might need to modify.
array = array.dup
array << 4

Beginner's Guide to Ruby