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?

More than 3 years have passed since last update.

【Ruby】%wで配列を作る

Last updated at Posted at 2021-11-02

##環境
Ruby 3.0.2

##配列の書き方

%記法は、要素が文字列リテラルかシンボルリテラルの場合に限り配列表現ができる。

array1、array2ともに同じ結果になる

array1 = ['apple', 'grape', 'peach']
array2 = %w(apple grape peach)

#=> ["apple", "grape", "peach"]

丸カッコ以外でもいける

%w{...}
%w[...]
%w|...|

######小ネタ
wはwordから来ているらしい

##参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?