Represents a UUID value.

This is a very basic implementation of UUIDs and exists more or less just to encode and decode UUIDs from and to Cassandra.

If you want to generate UUIDs see Generator.

Inherits

Object

Classes

Direct Known Subclasses

Methods

self.

new

(uuid)

Creates a new UUID either from a string (expected to be on the standard 8-4-4-4-12 form, or just 32 characters without hyphens), or from a 128 bit number.

Parameters:
Name Type Details
uuid String a 32 char uuid
Raises:
Type Details
ArgumentError if the string does not conform to the expected format
Specifications:
Uuid can be created from a string
Uuid.new('a4a70900-24e1-11df-8924-001ff3591711').to_s.should == 'a4a70900-24e1-11df-8924-001ff3591711'
Uuid can be created from a string without hyphens
Uuid.new('a4a7090024e111df8924001ff3591711').to_s.should == 'a4a70900-24e1-11df-8924-001ff3591711'
Uuid raises an error if the string is shorter than 32 chars
expect { Uuid.new('a4a7090024e111df8924001ff359171') }.to raise_error(ArgumentError)
Uuid raises an error if the string is longer than 32 chars
expect { Uuid.new('a4a7090024e111df8924001ff35917111') }.to raise_error(ArgumentError)
Uuid raises an error if the string is not a hexadecimal number
expect { Uuid.new('a4a7090024e111df8924001ff359171x') }.to raise_error(ArgumentError)
Uuid can be created from a number
Uuid.new(276263553384940695775376958868900023510).to_s.should == 'cfd66ccc-d857-4e90-b1e5-df98a3d40cd6'.force_encoding(::Encoding::ASCII)

to_s

Returns a string representation of this UUID in the standard 8-4-4-4-12 form.

Specifications:
Uuid#to_s returns a UUID standard format
Uuid.new('a4a70900-24e1-11df-8924-001ff3591711').to_s.should == 'a4a70900-24e1-11df-8924-001ff3591711'
Uuid#to_s returns an ASCII string
s = Uuid.new('a4a70900-24e1-11df-8924-001ff3591711').to_s
s.encoding.should == Encoding::ASCII

value

aliased as: to_i

Returns the numerical representation of this UUID

Returns:
Type Details
Bignum the 128 bit numerical representation
Specifications:
Uuid#value returns the numeric value
Uuid.new('cfd66ccc-d857-4e90-b1e5-df98a3d40cd6').value.should == 276263553384940695775376958868900023510
Uuid#value is aliased as #to_i
Uuid.new('cfd66ccc-d857-4e90-b1e5-df98a3d40cd6').to_i.should == 276263553384940695775376958868900023510