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

hash

Specifications:
Uuid#hash calculates a 64 bit hash of the UUID
h = Uuid.new(162917432198567078063626261009205865234).hash
h.should be < 2**63
h.should be > -2**63
Uuid#hash has the same hash code when #eql?
uuid1 = Uuid.new('a4a70900-24e1-11df-8924-001ff3591711')
uuid2 = Uuid.new('a4a70900-24e1-11df-8924-001ff3591711')
uuid1.hash.should == uuid2.hash
Uuid#hash has a different hash when not #eql?
uuid1 = Uuid.new('a4a70900-24e1-11df-8924-001ff3591711')
uuid2 = Uuid.new('b4a70900-24e1-11df-8924-001ff3591711')
uuid1.hash.should_not == uuid2.hash

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