Percent_expression.rb
This content was produced by an LLM and could include errors.
このスクリプトは %w(単語配列)・%W・%i(シンボル配列)・%I の違いを示します。小文字の %w/%i は式展開されず "#{str}" がリテラルのまま要素になり、大文字の %W/%I は変数 str の値が展開されて "ruby"・:ruby になります。つまり大文字版だけがダブルクオート内の補間を有効にします。
str='ruby'
#=> "ruby"
%w(a b c "#{str}")
#=> ["a", "b", "c", "\"\#{str}\""]
%W(a b c "#{str}")
#=> ["a", "b", "c", "\"ruby\""]
%i(a b c "#{str}")
#=> [:a, :b, :c, :"\"\#{str}\""]
%I(a b c "#{str}")
#=> [:a, :b, :c, :"\"ruby\""]
Ruby 4.0.6