Skip to content

Commit

Permalink
Make Memoist.escape_punctuation compatible with MRI 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 4, 2019
1 parent 510cb57 commit a893ce6
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 a893ce6

Please sign in to comment.