In Ruby, what does it mean for a String
or Array
(etc) object to be 'Frozen'? How/where is this property set or modified?
It means you cannot modify it. You set it by freeze
method.
s = "a"
concat
modifies the string instance.
s.concat("b")
# => "ab"
When you freeze the string:
s.freeze
then, you cannot apply concat
any more.
s.concat("c")
# => RuntimeError: can't modify frozen String
However, you can apply methods that do not modify the receiver:
s + "c"
# => "abc"
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