読者です 読者をやめる 読者になる 読者になる

日常

ケ・セラ・セラ

rails ActiveSupport 便利な String の活用形のメモ

rails
[8] pry(main)> (:user_follows).to_s.singularize
=> "user_follow"
[9] pry(main)> (:user_follows).to_s.pluralize
=> "user_follows"
[10] pry(main)> (:user_follows).to_s.camelize
=> "UserFollows"
[11] pry(main)> (:user_follows).to_s.classify
=> "UserFollow"
[12] pry(main)> "backoffice/session".camelize
=> "Backoffice::Session"
[13] pry(main)> :user_follows.to_s.camelize(:lower)
=> "userFollows"
[14] pry(main)> :user_follows.to_s.camelize(:upper)
=> "UserFollows"
[15] pry(main)> "AdminUser".underscore
=> "admin_user"
[16] pry(main)> "Backoffice::Session".underscore
=> "backoffice/session"
[17] pry(main)> "alice in wonderland".titleize
=> "Alice In Wonderland"
[18] pry(main)> "fermat's enigma".titleize
=> "Fermat's Enigma"
[19] pry(main)> "fermat's enigma".titlecase
=> "Fermat's Enigma"
[20] pry(main)> "contact_data".dasherize
=> "contact-data"
[21] pry(main)> "John Smith".parameterize
=> "john-smith"
[22] pry(main)> "Kurt Gödel".parameterize
=> "kurt-godel"
[23] pry(main)> "InvoiceLine".tableize
=> "invoice_lines"
[24] pry(main)> "invoice_lines".classify
=> "InvoiceLine"
[25] pry(main)> "User".foreign_key
=> "user_id"
[26] pry(main)> "User".foreign_key(false) # => "userid"
=> "userid"