Skip to content

Commit 946c823

Browse files
committed
Freeze Random::Formatter::ALPHANUMERIC and its elements
1 parent 784bd9c commit 946c823

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/random/formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def uuid_v7(extra_timestamp_bits: 0)
340340
end
341341

342342
# The default character list for #alphanumeric.
343-
ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9']
343+
ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9'].map(&:freeze).freeze
344344

345345
# Generate a random alphanumeric string.
346346
#

test/ruby/test_random_formatter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ class TestClassMethods < Test::Unit::TestCase
165165
def setup
166166
@it = Random
167167
end
168+
169+
def test_alphanumeric_frozen
170+
assert_predicate @it::Formatter::ALPHANUMERIC, :frozen?
171+
assert @it::Formatter::ALPHANUMERIC.all?(&:frozen?)
172+
end
168173
end
169174

170175
class TestInstanceMethods < Test::Unit::TestCase

0 commit comments

Comments
 (0)