LoginSignup
0
0

More than 5 years have passed since last update.

[RUBY] %記法 

Posted at

%記法

「’ ‘」や「” “」に対するエスケープを省略するためのもの。

%w

文字列の配列の("")
などを省略することができる。

例:

puts ["test1", "test2", "test3"]

%wを使えばスッキリ書くことができる。

puts %w(test1 test2 test3)

また、%Wと%wの違いは以下の通り。

%W→変数の式展開あり
%w→変数の式展開なし

%と%Q

「” “」(ダブルクォーテーション)の代替をする。

例:

puts "\"テスト\" \"サンプル\""
puts %("テスト","サンプル")

さいごに

まぁ、%wがめちゃ便利だということがわかりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0