I am using the # frozen_string_literal: true magic comment that RuboCop enforces by default, and I can't append something to a string:
string = 'hello'
string << ' world'
because it errors out with:
can't modify frozen String (RuntimeError)
You add a + before the string like:
string = +'hello'
string << ' world'
puts(string)
hello world
You can also use +=:
s = 'H'
s += 'ello
=> "Hello"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With