Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | String | capitalize!

概要

String#capitalize! -> self | nil

詳細

文字列先頭の文字を大文字に、残りを小文字に変更。
アルファベット以外の文字はそのまま

サンプルコード
require 'tbpgr_utils'


bulk_puts_eval binding, <<-EOS
hoge = 'hoge'
hoge.capitalize
hoge
hoge = 'hoge'
hoge.capitalize!
hoge
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

hoge = 'hoge'    # => "hoge"
hoge.capitalize  # => "Hoge"
hoge             # => "hoge"
hoge = 'hoge'    # => "hoge"
hoge.capitalize! # => "Hoge"
hoge             # => "Hoge"