Module: Pay::NanoId

Defined in:
lib/pay/nano_id.rb

Constant Summary collapse

ALPHABET =

Generates unique IDs - faster than UUID

"_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".freeze
ALPHABET_SIZE =
ALPHABET.size

Class Method Summary collapse

Class Method Details

.generate(size: 21) ⇒ Object



7
8
9
10
11
# File 'lib/pay/nano_id.rb', line 7

def self.generate(size: 21)
  id = ""
  size.times { id << ALPHABET[(Random.rand * ALPHABET_SIZE).floor] }
  id
end