LoginSignup
7
4

More than 5 years have passed since last update.

改行区切りの文字列の1行目をTitle、それ以降をBodyとして取得する

Last updated at Posted at 2017-03-10
title, *, body = "1行目\n2行目\n3行目".partition("\n")
puts title # => 1行目
puts body # => 2行目\n3行目

:eyes: https://ruby-doc.org/core-2.4.0/String.html#method-i-partition
:eyes: Rubyの多重代入あれこれまとめ - Qiita

コメント欄も見て行ってくれよな!

7
4
5

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
7
4