|
|
||
----------------------------------------------------- String#capitalize! str.capitalize! => str or nil ------------------------------------------------------------------------ Modifies _str_ by converting the first character to uppercase and the remainder to lowercase. Returns nil if no changes are made. a = "hello" a.capitalize! #=> "Hello" a #=> "Hello" a.capitalize! #=> nil
String#capitalize! --- capitalize --- capitalize! 先頭の文字を(アルファベットであれば)大文字に、残りを小文字に変更します。 capitalize は変更後の文字列を生成して返します。 capitalize! は self を変更して返しますが、変更が起こら なかった場合は nil を返します。 p "foobar".capitalize # => "Foobar" $KCODE が適切に設定されていなければ、漢字コードの一部も変換 してしまいます(これは、ShiftJIS コードで起こり得ます)。 逆に、$KCODE を設定してもマルチバイト文字のアルファベット は処理しません。 # -*- Coding: shift_jis -*- $KCODE ='n' puts "帰".capitalize # => 蟻 upcase, downcase, swapcase も参照してください。