本文簡要介紹ruby語言中 Random::Formatter.urlsafe_base64
的用法。
用法
urlsafe_base64(n=nil, padding=false)
Random::Formatter#urlsafe_base64
生成隨機 URL-safe base64 字符串。
參數n
指定要生成的隨機數的長度(以字節為單位)。結果字符串的長度約為 n
的 4/3。
如果 n
未指定或為零,則假定為 16。未來可能會更大。
布爾參數 padding
指定填充。如果為 false 或 nil,則不會生成填充。否則會生成填充。默認情況下,不會生成填充,因為 “=” 可能用作 URL 分隔符。
結果可能包含A-Z、a-z、0-9、“-”和“_”。如果padding
為真,也使用“=”。
require 'random/formatter'
prng.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
有關URL-safe base64 的定義,請參見 RFC 3548。
相關用法
- Ruby Formatter.uuid用法及代碼示例
- Ruby Formatter.random_bytes用法及代碼示例
- Ruby Formatter.base64用法及代碼示例
- Ruby Formatter.hex用法及代碼示例
- Ruby Formatter.alphanumeric用法及代碼示例
- Ruby Formatter.choose用法及代碼示例
- Ruby Formatter模塊用法及代碼示例
- Ruby Float arg()用法及代碼示例
- Ruby File.identical?用法及代碼示例
- Ruby Fiber.schedule用法及代碼示例
- Ruby Float fdiv()用法及代碼示例
- Ruby Float quo()用法及代碼示例
- Ruby Float angle()用法及代碼示例
- Ruby FileUtils.mkdir用法及代碼示例
- Ruby Float divmod()用法及代碼示例
- Ruby Float.self - other用法及代碼示例
- Ruby Float.rationalize用法及代碼示例
- Ruby Float.truncate用法及代碼示例
- Ruby FileUtils.compare_file用法及代碼示例
- Ruby FileUtils.options_of用法及代碼示例
- Ruby File.dirname用法及代碼示例
- Ruby Float prev_float()用法及代碼示例
- Ruby FileUtils.ln_s用法及代碼示例
- Ruby Float round()用法及代碼示例
- Ruby Float denominator()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Formatter.urlsafe_base64。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。