Method: LexicalUUID#initialize
- Defined in:
- lib/lexical_uuid.rb
#initialize(timestamp = nil, worker_id = nil, timestamp_factory = IncreasingMicrosecondClock) ⇒ LexicalUUID
Returns a new instance of LexicalUUID.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lexical_uuid.rb', line 23 def initialize( = nil, worker_id = nil, = IncreasingMicrosecondClock) case when Fixnum, Bignum = @worker_id = worker_id || self.class.worker_id when String case .size when 16 from_bytes() when 36 elements = .split("-") from_bytes(Array(elements.join).pack('H32')) else raise ArgumentError, "#{timestamp} was incorrectly sized. Must be 16 timestamp." end when Time = .stamp @worker_id = self.class.worker_id when nil @worker_id = self.class.worker_id = .call end end |