README

struct UUID

Overview

Represents a UUID (Universally Unique IDentifier).

Defined in:

uuid.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Struct

==(other) : Bool ==, hash(hasher) hash, inspect(io : IO) : Nil inspect, pretty_print(pp) : Nil pretty_print, to_s(io) to_s

Instance methods inherited from struct Value

==(other : JSON::Any)
==(other : YAML::Any)
==(other)
==
, dup dup

Instance methods inherited from class Object

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other)
===
, =~(other) =~, class class, dup dup, hash(hasher)
hash
hash
, inspect(io : IO)
inspect
inspect
, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json
to_json
, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ")
to_pretty_json
, to_s
to_s(io : IO)
to_s
, to_yaml(io : IO)
to_yaml
to_yaml
, try(&block) try, unsafe_as(type : T.class) forall T unsafe_as

Constructor methods inherited from class Object

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self
from_json
, from_yaml(string_or_io : String | IO) : self from_yaml

Constructor Detail

def self.new(bytes : StaticArray(UInt8, 16), variant : UUID::Variant? = nil, version : UUID::Version? = nil) #

Generates UUID from bytes, applying version and variant to the UUID if present.


[View source]
def self.new(slice : Slice(UInt8), variant = nil, version = nil) #

Creates UUID from 16-bytes slice. Raises if slice isn't 16 bytes long. See #initialize for variant and version.


[View source]
def self.new(uuid : UUID, variant = nil, version = nil) #

Creates another UUID which is a copy of uuid, but allows overriding variant or version.


[View source]
def self.new(value : String, variant = nil, version = nil) #

Creates new UUID by decoding value string from hyphenated (ie. ba714f86-cac6-42c7-8956-bcf5105e1b81), hexstring (ie. 89370a4ab66440c8add39e06f2bb6af6) or URN (ie. urn:uuid:3f9eaf9e-cdb0-45cc-8ecb-0e5b2bfb0c20) format.


[View source]

Class Method Detail

def self.empty #

[View source]
def self.random(random = Random::Secure, variant = Variant::RFC4122, version = Version::V4) #

Generates RFC 4122 v4 UUID.

It is strongly recommended to use a cryptographically random source for random, such as Random::Secure.


[View source]

Instance Method Detail

def ==(other : UUID) #

Returns true if other UUID represents the same UUID, false otherwise.


[View source]
def hexstring #

[View source]
def to_s(io : IO) #

[View source]
def to_slice #

Returns 16-byte slice.


[View source]
def to_unsafe #

Returns unsafe pointer to 16-bytes.


[View source]
def urn #

[View source]
def v1! #

Returns true if UUID looks is a V1, raises Error otherwise.


[View source]
def v1? #

Returns true if UUID looks is a V1, false otherwise.


[View source]
def v2! #

Returns true if UUID looks is a V2, raises Error otherwise.


[View source]
def v2? #

Returns true if UUID looks is a V2, false otherwise.


[View source]
def v3! #

Returns true if UUID looks is a V3, raises Error otherwise.


[View source]
def v3? #

Returns true if UUID looks is a V3, false otherwise.


[View source]
def v4! #

Returns true if UUID looks is a V4, raises Error otherwise.


[View source]
def v4? #

Returns true if UUID looks is a V4, false otherwise.


[View source]
def v5! #

Returns true if UUID looks is a V5, raises Error otherwise.


[View source]
def v5? #

Returns true if UUID looks is a V5, false otherwise.


[View source]
def variant #

Returns UUID variant.


[View source]
def version #

Returns version based on RFC4122 format. See also #variant.


[View source]