struct UUID

Overview

Represents a UUID (Universally Unique IDentifier).

NOTE To use UUID, you must explicitly import it with require "uuid"

Included Modules

Defined in:

uuid_utils.cr

Class Method Summary

Class Method Detail

def self.uuid3(ns : UUID | Namespace, value) #

Generate a UUID from the MD5 hash of a namespace UUID and a name.

Example:

require "uuid_utils"

namespace = UUID.new("68ab717d-d847-4277-be1a-303be8ac3d97")
msg = "Hello World!"
puts UUID.uuid3(namespace, msg) # => 33056d85-5061-31c8-9656-df07f3eec397

[View source]
def self.uuid4 #

Generate a random UUID.

Example:

require "uuid_utils"

puts UUID.uuid4 # => 39e54402-44c6-42c6-be52-4bb9ab18a5fa

[View source]
def self.uuid5(ns : UUID | Namespace, value) #

Generate a UUID from the SHA-1 hash of a namespace UUID and a name.

Example:

require "uuid_utils"

namespace = UUID.new("68ab717d-d847-4277-be1a-303be8ac3d97")
msg = "Hello World!"
puts UUID.uuid5(namespace, msg) # => 562ed049-5b55-582d-ba51-812a786927ca

[View source]