Skip to content

Commit

Permalink
Merge pull request #82 from casperisfine/mri-27-frozen-string
Browse files Browse the repository at this point in the history
Make Memoist.escape_punctuation compatible with MRI 2.7

The latest ruby-2.7 preview included some changes to `Symbol#to_s` so that it returns a frozen string [1].

This PR fixes an issue with the `Memoist.escape_punctuation` method so that we can maintain compatibility with this new behaviour potentially being introduced in Ruby 2.7.

[1]  https://bugs.ruby-lang.org/issues/16150
  • Loading branch information
sebjacobs authored Nov 4, 2019
2 parents 510cb57 + a893ce6 commit ee0c80a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/memoist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def self.unmemoized_prefix(identifier = nil)
end

def self.escape_punctuation(string)
string = string.is_a?(String) ? string.dup : string.to_s
string = string.to_s

return string unless string.end_with?('?'.freeze, '!'.freeze)

string = string.dup if string.frozen?

# A String can't end in both ? and !
if string.sub!(/\?\Z/, '_query'.freeze)
else
Expand Down

0 comments on commit ee0c80a

Please sign in to comment.