diff --git a/lib/memoist.rb b/lib/memoist.rb index 54b67e6..fcd3141 100644 --- a/lib/memoist.rb +++ b/lib/memoist.rb @@ -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