ulid-ruby
ulid-ruby copied to clipboard
Add support for raw bytes, UUID and int128 forms
A ULID is nothing more than an uInt128 with encoding convenience. This PR enables the conversion to / from UUID forms to a ULID. Likewise enables support of the BigNum (int128) decimal form.
The following are all the same:
ULID.new(1777022035688232904178850488005232350)
ULID.new("\x01V=\xF3c\x00\xD2\x19\\C\xB6\xCA\xFF\x95\x06\xDE")
ULID.new("01563df3-6300-d219-5c43-b6caff9506de")
ULID.new("01ARYZ6RR0T8CNRGXPSBZSA1PY")
Likewise:
token = ULID.new("01ARYZ6RR0T8CNRGXPSBZSA1PY")
token.ulid # "01ARYZ6RR0T8CNRGXPSBZSA1PY"
token.to_uuid # "01563df3-6300-d219-5c43-b6caff9506de"
token.to_i # 1777022035688232904178850488005232350
token.bytes # "\x01V=\xF3c\x00\xD2\x19\\C\xB6\xCA\xFF\x95\x06\xDE"
# 01ARYZ6RR0T8CNRGXPSBZSA1PY