Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Memoist.escape_punctuation compatible with MRI 2.7 #82

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is worth retaining these explicit .freeze calls for older versions of ruby (2.2 and below). If not then it would be good to add something to the commit message which explains the reasoning behind dropping them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you are right, I'll add them back.

else
Expand Down