Ruby 1.8.7 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Stringクラス > rstrip

instance method String#rstrip

rstrip -> String

文字列の末尾にある空白文字を全て取り除いた新しい文字列を返します。 空白文字の定義は " \t\r\n\f\v\0" です。

例:

p "  abc\n".rstrip          #=> "  abc"
p "  abc \t\r\n\0".rstrip   #=> "  abc"
p "  abc".rstrip            #=> "  abc"
p "  abc\0 ".rstrip         #=> "  abc\0"

str = "abc\n"
p str.rstrip    #=> "abc"
p str           #=> "abc\n"  (元の文字列は変化しない)

[SEE_ALSO] String#lstrip,String#strip

class String