LoginSignup
76

More than 5 years have passed since last update.

Rails キャメルケースとスネークケースを変換する

Posted at

自分向けのメモ

UpdateBalance(キャメルケース)をupdate_balance(スネークケース)に変換する例

str.underscore #スネークケースにする
str.camelize #キャメルケースにする

他にも

singularize   #単数形にする
pluralize     #複数形にする
tableize      #テーブル名にする(pluralize + underscore)
classify      #モデル名にする(singularize + camerize)
constantize   #その名前の定数にする

などあるらしい。


参考

Railsらしく書こう

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
76