Rubyのchompメソッド
chompメソッドは、文字列の末尾の改行文字を取り除いた新しい文字列を返す。
\n
\r\n
\r
を取り除く。
input = gets # Helloと入力してリターンキーを押す input = input.chomp input #=> "Hello"
input = gets.chomp
でも可。
\n
\r
については
chomp!
はレシーバ自身を変更する。
戻り値は、末尾に改行文字があった時はレシーバ自身。
なかった時はnil
\n
\r\n
\r
を取り除く。
input = gets # Helloと入力してリターンキーを押す input = input.chomp input #=> "Hello"
input = gets.chomp
でも可。
\n
\r
については
chomp!
はレシーバ自身を変更する。
戻り値は、末尾に改行文字があった時はレシーバ自身。
なかった時はnil