Skip to content

Commit 5b9f16d

Browse files
authored
Merge pull request #2619 from ksss/drop-undocumented-random
Update securerandom
2 parents ab2206c + 602be7a commit 5b9f16d

File tree

4 files changed

+48
-71
lines changed

4 files changed

+48
-71
lines changed

core/rbs/unnamed/random.rbs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,36 @@ module RBS
288288
#
289289
%a{annotate:rdoc:copy:Random::Formatter#uuid}
290290
def uuid: () -> String
291+
292+
# <!--
293+
# rdoc-file=lib/random/formatter.rb
294+
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
295+
# -->
296+
# Generate a random alphanumeric string.
297+
#
298+
# The argument *n* specifies the length, in characters, of the alphanumeric
299+
# string to be generated. The argument *chars* specifies the character list
300+
# which the result is consist of.
301+
#
302+
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
303+
# future.
304+
#
305+
# The result may contain A-Z, a-z and 0-9, unless *chars* is specified.
306+
#
307+
# require 'random/formatter'
308+
#
309+
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
310+
# # or
311+
# prng = Random.new
312+
# prng.alphanumeric(10) #=> "i6K93NdqiH"
313+
#
314+
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
315+
# # or
316+
# prng = Random.new
317+
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
318+
#
319+
%a{annotate:rdoc:copy:Random::Formatter#alphanumeric}
320+
def alphanumeric: (?Numeric?, ?chars: Array[String]) -> String
291321
end
292322
end
293323
end

stdlib/securerandom/0/securerandom.rbs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,4 @@
3636
#
3737
module SecureRandom
3838
extend Random::Formatter
39-
40-
# <!--
41-
# rdoc-file=lib/securerandom.rb
42-
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
43-
# -->
44-
# Compatibility methods for Ruby 3.2, we can remove this after dropping to
45-
# support Ruby 3.2
46-
#
47-
def self.alphanumeric: (?Integer?) -> String
48-
49-
def self.base64: (?Integer?) -> String
50-
51-
def self.hex: (?Integer?) -> String
52-
53-
def self.random_bytes: (?Integer?) -> String
54-
55-
def self.random_number: () -> Float
56-
| (Integer) -> Integer
57-
| (Numeric) -> Numeric
58-
59-
def self.urlsafe_base64: (?Integer?, ?bool?) -> String
60-
61-
def self.uuid: () -> String
6239
end

test/stdlib/Random_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def test_urandom
3838
assert_send_type "(::Integer) -> ::String",
3939
Random, :urandom, 0
4040
end
41+
42+
def test_alphanumeric
43+
assert_send_type "() -> ::String",
44+
Random, :alphanumeric
45+
assert_send_type "(::Integer) -> ::String",
46+
Random, :alphanumeric, 10
47+
assert_send_type "(::Integer, chars: Array[::String]) -> ::String",
48+
Random, :alphanumeric, 10, chars: ["a", "b", "c"]
49+
end
4150
end
4251

4352
class RandomTest < Test::Unit::TestCase
@@ -73,4 +82,13 @@ def test_seed
7382
assert_send_type "() -> ::Integer",
7483
Random.new, :seed
7584
end
85+
86+
def test_alphanumeric
87+
assert_send_type "() -> ::String",
88+
Random.new, :alphanumeric
89+
assert_send_type "(::Integer) -> ::String",
90+
Random.new, :alphanumeric, 10
91+
assert_send_type "(::Integer, chars: Array[::String]) -> ::String",
92+
Random.new, :alphanumeric, 10, chars: ["a", "b", "c"]
93+
end
7694
end

test/stdlib/SecureRandom_test.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)