Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created June 7, 2024 22:01
Show Gist options
  • Save mikebaldry/66fe37006e9bd3d574f4451b1082d57e to your computer and use it in GitHub Desktop.
Save mikebaldry/66fe37006e9bd3d574f4451b1082d57e to your computer and use it in GitHub Desktop.
> ./ruby test.rb
test.rb:9: warning: 'sub!' called on a string that could, in the future be frozen. string created at test.rb:4
test.rb:14: warning: '[]=' called on a string that could, in the future be frozen. string created at test.rb:4
# frozen_string_literal: warn
from_a_dynamic = "Hello, #{(1..100).to_a.sample}!"
from_a_literal = "Hello, world!"
dup_from_a_literal = from_a_literal.dup
dup_from_a_dynamic = from_a_dynamic.dup
from_a_literal.sub!(/world/, "Ruby!")
dup_from_a_literal.sub!(/world/, "Ruby!")
from_a_dynamic.sub!(/world/, "Ruby!")
dup_from_a_dynamic.sub!(/world/, "Ruby!")
from_a_literal[4] = "Y"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment