Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created December 2, 2011 22:49
Show Gist options
  • Save ahoward/1425207 to your computer and use it in GitHub Desktop.
Save ahoward/1425207 to your computer and use it in GitHub Desktop.
just gimme a damn uuid
{
'ffi-uuid' => proc{|*args| FFI::UUID.generate_time.to_s},
'uuid' => proc{|*args| UUID.generate.to_s},
'uuidtools' => proc{|*args| UUIDTools::UUID.timestamp_create.to_s}
}.each do |lib, implementation|
begin
require(lib)
define_method(:uuid, &implementation)
break
rescue LoadError
nil
end
end
abort 'no suitable uuid generation library detected' unless method_defined?(:uuid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment