1
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.

RailsGuidesのActiveSupportのStringの拡張を読んだ記録

1
Last updated at Posted at 2017-10-16

Active Support コア拡張機能 | Rails ガイド#Stringの拡張
を読んだ感想をだらだら書くよ!

String#remove

.rb
"Hello World".remove(/Hello /) # => "World"

"Hello World".gsub(/Hello /, '') とかよくやりがちなので積極活用する

String#squish

squishメソッドは、冒頭と末尾のホワイトスペースを除去し、連続したホワイトスペースを1つに減らします。

.rb
" \n  foo\n\r \t bar \n".squish # => "foo bar"

便利!

String#strip-heredoc

2.3 から <<~ で squiggly heredoc に対応しているので、もはや不要

String#titleize

titleizeメソッドは、レシーバの語の1文字目を大文字にします。

いつか使いそう

そんな感じ

1
0
1

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
1
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?