diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-05-18 16:14:44 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-12-16 20:54:40 +0900 |
commit | 946c823ddbd2f9bd9429d7d1b229a5ba773e540f (patch) | |
tree | 331d1089ad7c4370821e68a55236ac33c61c3462 | |
parent | 784bd9c42ebc58c5ba6f40d9600b9591db81c8d8 (diff) |
Freeze `Random::Formatter::ALPHANUMERIC` and its elements
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12356
-rw-r--r-- | lib/random/formatter.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_random_formatter.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/random/formatter.rb b/lib/random/formatter.rb index 2b5cf718ad..4ecd6ad027 100644 --- a/lib/random/formatter.rb +++ b/lib/random/formatter.rb @@ -340,7 +340,7 @@ module Random::Formatter end # The default character list for #alphanumeric. - ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9'] + ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9'].map(&:freeze).freeze # Generate a random alphanumeric string. # diff --git a/test/ruby/test_random_formatter.rb b/test/ruby/test_random_formatter.rb index f927522d96..784fbfc2b8 100644 --- a/test/ruby/test_random_formatter.rb +++ b/test/ruby/test_random_formatter.rb @@ -165,6 +165,11 @@ module Random::Formatter def setup @it = Random end + + def test_alphanumeric_frozen + assert_predicate @it::Formatter::ALPHANUMERIC, :frozen? + assert @it::Formatter::ALPHANUMERIC.all?(&:frozen?) + end end class TestInstanceMethods < Test::Unit::TestCase |