Created
May 6, 2021 11:04
-
-
Save alec-c4/dca0d9305d23a80450e10de9b53415c0 to your computer and use it in GitHub Desktop.
string to id (both integer and UUID)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.class_eval do | |
def to_id | |
if self.match?(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i) | |
self.to_s | |
else | |
self.to_i | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment