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 5 years have passed since last update.

Rubyの改行はそのまま出力される

Posted at

printの引数内で改行すると…?

printの引数で改行するには以下のように「\n」を入れる必要がある。

sample.rb
print("Hello,\nHogehoge\n")

んで、以下のコードでこれと同じ出力ができる。

sample_rewrite.rb
print("Hello,
Hogehoge\n")

書き方的に汚いと思ったものの、「\n」を複数回挟むことがあるなら有用かも…?

ひねくれてないで素直に書け

ま、こう書いた方が素直ですな。

print2puts.rb
puts("Hello,")
puts("Hogehoge")
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?