generate uuid in ruby

To generate a UUID (Universally Unique Identifier) in Ruby, we can use the uuid gem which can be installed by running gem install uuid.

Here's an example code snippet that generates a random UUID:

main.rb
require 'uuid'

uuid = UUID.new.generate
puts uuid
51 chars
5 lines

This will output a string consisting of 32 hexadecimal digits separated by hyphens, like so:

main.rb
2bd45467-8e47-4639-9fcb-1f49fe8b4441
37 chars
2 lines

Each UUID generated using this method will be unique and random.

gistlibby LogSnag