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 | split の引数を省略する

Last updated at Posted at 2016-05-02

省略すると

split(/\s/).reject(&:empty?)

と書いた時と、似た動作になるようだ。

検証

スペースを区切り文字として扱ってくれる。

"A B C D E".split

# => ["A", "B", "C", "D", "E"]

改行も区切り文字として扱われる。
区切り文字が混在・連続していても、いい感じで扱ってくれる。

" A\nB\r  C  \r\nD E ".split

# => => ["A", "B", "C", "D", "E"]

参考

環境

  • ruby 2.3.0

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

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?