90
77

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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らしく書こう

90
77
0

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
90
77

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?