Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions core/rbs/unnamed/random.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,36 @@ module RBS
#
%a{annotate:rdoc:copy:Random::Formatter#uuid}
def uuid: () -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
# -->
# Generate a random alphanumeric string.
#
# The argument *n* specifies the length, in characters, of the alphanumeric
# string to be generated. The argument *chars* specifies the character list
# which the result is consist of.
#
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
# future.
#
# The result may contain A-Z, a-z and 0-9, unless *chars* is specified.
#
# require 'random/formatter'
#
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
# # or
# prng = Random.new
# prng.alphanumeric(10) #=> "i6K93NdqiH"
#
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
# # or
# prng = Random.new
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
#
%a{annotate:rdoc:copy:Random::Formatter#alphanumeric}
def alphanumeric: (?Numeric?, ?chars: Array[String]) -> String
end
end
end
23 changes: 0 additions & 23 deletions stdlib/securerandom/0/securerandom.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,4 @@
#
module SecureRandom
extend Random::Formatter

# <!--
# rdoc-file=lib/securerandom.rb
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
# -->
# Compatibility methods for Ruby 3.2, we can remove this after dropping to
# support Ruby 3.2
#
def self.alphanumeric: (?Integer?) -> String

def self.base64: (?Integer?) -> String

def self.hex: (?Integer?) -> String

def self.random_bytes: (?Integer?) -> String

def self.random_number: () -> Float
| (Integer) -> Integer
| (Numeric) -> Numeric

def self.urlsafe_base64: (?Integer?, ?bool?) -> String

def self.uuid: () -> String
end
18 changes: 18 additions & 0 deletions test/stdlib/Random_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def test_urandom
assert_send_type "(::Integer) -> ::String",
Random, :urandom, 0
end

def test_alphanumeric
assert_send_type "() -> ::String",
Random, :alphanumeric
assert_send_type "(::Integer) -> ::String",
Random, :alphanumeric, 10
assert_send_type "(::Integer, chars: Array[::String]) -> ::String",
Random, :alphanumeric, 10, chars: ["a", "b", "c"]
end
end

class RandomTest < Test::Unit::TestCase
Expand Down Expand Up @@ -73,4 +82,13 @@ def test_seed
assert_send_type "() -> ::Integer",
Random.new, :seed
end

def test_alphanumeric
assert_send_type "() -> ::String",
Random.new, :alphanumeric
assert_send_type "(::Integer) -> ::String",
Random.new, :alphanumeric, 10
assert_send_type "(::Integer, chars: Array[::String]) -> ::String",
Random.new, :alphanumeric, 10, chars: ["a", "b", "c"]
end
end
48 changes: 0 additions & 48 deletions test/stdlib/SecureRandom_test.rb

This file was deleted.

Loading