module BetterUUID::InstanceMethods
Public Instance Methods
<=>(other)
click to toggle source
UUIDs are comparable (don’t know what benefits are there, though).
# File lib/better-uuid/instance_methods.rb, line 81 def <=>(other) to_s <=> other.to_s end
==(other)
click to toggle source
Two UUIDs are said to be equal if and only if their (byte-order canonicalized) integer representations are equivallent. Refer RFC4122 for details.
# File lib/better-uuid/instance_methods.rb, line 75 def ==(other) to_i == other.to_i end
to_int()
click to toggle source
Convert into 128-bit unsigned integer Typically a Bignum instance, but can be a Fixnum.
# File lib/better-uuid/instance_methods.rb, line 55 def to_int tmp = self.raw_bytes.unpack 'C*' tmp.inject do |r, i| r * 256 | i end end
Also aliased as: to_i
to_s()
click to toggle source
Generate the string representation (a.k.a GUID) of this UUID
# File lib/better-uuid/instance_methods.rb, line 39 def to_s a = unpack tmp = a[-1].unpack 'C*' a[-1] = sprintf '%02x%02x%02x%02x%02x%02x', *tmp '%08x-%04x-%04x-%02x%02x-%s' % a end
Also aliased as: guid
to_uri()
click to toggle source
Convert into a RFC4122-comforming URN representation
# File lib/better-uuid/instance_methods.rb, line 48 def to_uri 'urn:uuid:' + self.to_s end
Also aliased as: urn
unpack()
click to toggle source
The ‘primitive deconstructor’, or the dual to pack. Note UUID.pack(uuid.unpack) == uuid
# File lib/better-uuid/instance_methods.rb, line 34 def unpack raw_bytes.unpack 'NnnCCa6' end
version()
click to toggle source
Gets the version of this UUID returns nil if bad version
# File lib/better-uuid/instance_methods.rb, line 65 def version a = unpack v = (a[2] & 0xF000).to_s(16)[0].chr.to_i return v if (1..5).include? v return nil end