Ruby 2.6.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Stringクラス > strip!
strip! -> self | nil
[permalink][rdoc]先頭と末尾の空白文字を全て破壊的に取り除きます。空白文字の定義は " \t\r\n\f\v\0" です。
strip! は、内容を変更した self を返します。ただし取り除く空白がなかったときは nil を返します。
str = " abc\r\n"
p str.strip! #=> "abc"
p str #=> "abc"
str = "abc"
p str.strip! #=> nil
p str #=> "abc"
str = " \0 abc \0"
str.strip!
p str #=> "abc"
[SEE_ALSO] String#strip, String#lstrip