Skip to content

Commit

Permalink
Avoid spurious frozen string literal deprecation warnings on Ruby 3.4…
Browse files Browse the repository at this point in the history
….0-preview2+
  • Loading branch information
jeremyevans committed Oct 8, 2024
1 parent 69465bf commit 346b91f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## master

* Avoid spurious frozen string literal deprecation warning on Ruby 3.4.0-preview2+ (jeremyevans)

## 2.4.0 (2024-06-27)

* Support commonmarker 1.0+ API (unasuke) (#10)
Expand Down
20 changes: 17 additions & 3 deletions lib/tilt/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def initialize(file=nil, line=nil, options=nil)

if @data.respond_to?(:force_encoding)
if default_encoding
@data = @data.dup if @data.frozen?
@data = _dup_string_if_frozen(@data)
@data.force_encoding(default_encoding)
end

Expand Down Expand Up @@ -267,6 +267,18 @@ def precompiled_postamble(local_keys)

private

if RUBY_VERSION >= '2.3'
def _dup_string_if_frozen(string)
+string
end
# :nocov:
else
def _dup_string_if_frozen(string)
string.frozen? ? string.dup : string
end
end
# :nocov:

def process_arg(arg)
if arg
case
Expand Down Expand Up @@ -390,8 +402,10 @@ def extract_encoding(script, &block)
end

def extract_magic_comment(script)
if script.frozen?
script = script.dup
was_frozen = script.frozen?
script = _dup_string_if_frozen(script)

if was_frozen
yield script
end

Expand Down

0 comments on commit 346b91f

Please sign in to comment.