ActiveSupport
ActiveSupport
rubyのコアに機能追加(railsの一部)
gem 'activesupport'
require 'active_support'
ActiveSupportで追加される文字列操作一覧
table:文字列操作
"Hoge".underscore スネークケース化
"Hoge".camelize キャメルケース化
"Hoge".singularize 単数形
"Hoge".pluralize 複数形
"Hoge".tableize テーブル名に(pluralize + underscore)
"Hoge".classify モデル名に(singularize + camerize)
"Hoge".classify.constantize モデルオブジェクトの取得
"Hoge".constantize 定数化
Hash から文字列でもシンボルでも値を取り出す
sugoi_hash = { yuno: 'ゆの', miyako: '宮子' }.with_indifferent_access
ただし、form_builder系メソッド(Formヘルパ)のcollectionなどには、options.with_indifferent_accessにしてから渡すと認識しなくなるので注意・・・
railsでクラスがあるか無いか
const_defined?(model_name.classify)