0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

%記法 (Ruby)

Last updated at Posted at 2025-05-23

%記法について

%記法について調べたのでまとめます。
%記法はさまざまな種類のリテラル(文字列、配列、記号など)を簡潔に書ける構文です。

%q

シングルクォートの文字列リテラルを簡潔に書くためのものです。
式展開はしない。

%q(hello world) # => 'hello world'

%Q

ダブルクォートの文字列リテラルを簡潔に書くためのものです。
式展開はする。

name = "world"
%Q(hello #{name}) # => "hello world"

%w

文字列の配列を簡潔に書くものです。
式展開はしない。

%w(hello world) # => ['hello', 'world']

%W

文字列の配列を簡潔に書くものです。
式展開はする。

name = "world"
%W(hello #{name}) # => ["hello", "world"]

%i

シンボルの配列を簡潔に書くものです。
式展開はしない。

%i(hello world) # => [:hello, :world]

%I

シンボルの配列を簡潔に書くものです。
式展開はする。

name = "world"
%I(hello #{name}) # => [:hello :world]

まとめ

%記法を使用することで、簡潔に書くことができます。

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?