diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-12-16 13:48:36 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-12-16 05:35:47 +0000 |
| commit | 3a4433dddd4ba27d23feff83efd9d48604420df8 (patch) | |
| tree | 0cf6d4a68222d88e1581b26cae866dfe34318763 /lib | |
| parent | 5e838197a318503c3d53f8662353ff29c5c3bd4a (diff) | |
[ruby/securerandom] Restore SecureRandom.alphanumeric same as Random::Formatter.alphanumeric of Ruby 3.3/3.4
Fixes https://github.com/ruby/securerandom/pull/35
https://github.com/ruby/securerandom/commit/fbb36e36cc
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/securerandom.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb index db1fcaab02..0bcd2b6af0 100644 --- a/lib/securerandom.rb +++ b/lib/securerandom.rb @@ -51,6 +51,16 @@ module SecureRandom return gen_random(n) end + # Compatibility methods for Ruby 3.2, we can remove this after dropping to support Ruby 3.2 + def alphanumeric(n = nil, chars: ALPHANUMERIC) + if RUBY_VERSION < '3.3' + n = 16 if n.nil? + choose(chars, n) + else + super n, chars: chars + end + end + private # :stopdoc: |
