Friday, September 21, 2012

UUID in Ruby

There are 3 ways to deal UUID in Ruby.

(1) Use SecureRandom class

Check my article.

(2) Install uuid gem

Check Github page of uuid gem.

(3) [for JRuby] Using java.util.UUID

irb(main):001:0> require 'java'
irb(main):002:0> import java.util.UUID
irb(main):003:0> UUID.randomUUID.to_s
=> "e42ccfce-d6a0-4cb5-a0c0-9fae6ca05b84"
irb(main):003:0> UUID.randomUUID.to_s
=> "80a31bb3-3fce-4e6f-9c8a-5a819de45960"

No comments:

Post a Comment