Created
June 16, 2024 22:54
-
-
Save havenwood/3963ae150acf640385863838a2516426 to your computer and use it in GitHub Desktop.
A simple Nano ID implementation in Ruby
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
# frozen_string_literal: true | |
require 'securerandom' | |
module NanoID | |
ALPHABET = [*'A'..'Z', *'a'..'z', *'0'..'9', '_', '-'].freeze | |
module_function | |
def nano_id(alphabet: ALPHABET, size: 21) | |
SecureRandom.send(:choose, alphabet, size) | |
end | |
end | |
include NanoID | |
puts nano_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment