Heads up: This description was created by AI and might not be 100% accurate.
dow.rb
This Ruby code snippet demonstrates how to create a frozen array of strings in Ruby. The code creates an array called DOW_JP
and initializes it with the seven days of the week in Japanese, using the %w[]
syntax. It then uses the map()
method to freeze each element of the array, and finally freezes the entire array itself.
Note: Frozen objects are objects that cannot be modified after they have been created. In this case, the array DOW_JP
is frozen so that it can’t be changed or reassigned.
Ruby code snippet
DOW_JP = %w[日 月 火 水 木 金 土].map(&:freeze).freeze
#=> ["日", "月", "火", "水", "木", "金", "土"]
Executed with Ruby 3.4.4
.