1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/securerandom] Use String#unpack1

https://github.com/ruby/securerandom/commit/5460a18c35
This commit is contained in:
Nobuyoshi Nakada 2021-12-14 00:55:02 +09:00
parent 0ebbab23ba
commit 900e0c8c39
2 changed files with 3 additions and 3 deletions

View file

@ -71,7 +71,7 @@ module Random::Formatter
# prng.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
def hex(n=nil)
random_bytes(n).unpack("H*")[0]
random_bytes(n).unpack1("H*")
end
# Random::Formatter#base64 generates a random base64 string.

View file

@ -27,9 +27,9 @@ module Random::Formatter
end
def test_base64
assert_equal(16, @it.base64.unpack('m*')[0].size)
assert_equal(16, @it.base64.unpack1('m*').size)
17.times do |idx|
assert_equal(idx, @it.base64(idx).unpack('m*')[0].size)
assert_equal(idx, @it.base64(idx).unpack1('m*').size)
end
end