Getting can't modify frozen string when using string.insert
- by Richard
Hi,
This is a quick question. I have the following ruby code, which works fine.
def add_zeros number, zeros
number = number.to_s
zeros_to_add = zeros - number.length
zeros_to_add.times do
number = "0#{number}"
end
number
end
But if I replace
number = "0#{number}"
With
number.insert(0, "0")
Then I get TypeError: can't modify frozen string, does anyone know why this is?