Skip to content

Instantly share code, notes, and snippets.

@alec-c4
Created May 6, 2021 11:04
Show Gist options
  • Save alec-c4/dca0d9305d23a80450e10de9b53415c0 to your computer and use it in GitHub Desktop.
Save alec-c4/dca0d9305d23a80450e10de9b53415c0 to your computer and use it in GitHub Desktop.
string to id (both integer and UUID)
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