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のコードを書く上で知っていると便利なこと

Last updated at Posted at 2020-12-04

Rubyのコードを書く上で便利なことを参考書で学びましたので
勉強の記録用として記事にしてみました。
#%記法
##%w

> ary1 = ['apple', 'banana', 'orange']
> puts ary1
=> ["apple", "banana", "orange"]

> ary2 = %w(apple banana orange)
> p ary2
=> ["apple", "banana", "orange"]

すべての要素が文字列である配列は、通常の配列記法の他に、「%w」というキーワード使って書くことができます。

##%i

> ary1 = [:apple, :banana, :orange]
> puts ary1
=> [:apple, :banana, :orange]

> ary2 = %i(apple banana orange)
> p ary2
=> [:apple, :banana, :orange]

すべての要素がシンボルである配列は、「%i」というキーワード使って書くことができます。

%記法を使うことでソースコードに記述する文字数を少し減らすことができ、可読性が良くなります。

0
0
2

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?