Help us understand the problem. What is going on with this article?

動的にクラス名やテーブル名を取得・生成する際に便利なメソッド

More than 3 years have passed since last update.

String#pluralize

単数形から複数形に変換

irb(main):014:0> ['phone', 'wolf', 'fish', 'class'].map(&:pluralize)
=> ["phones", "wolves", "fish", "classes"]

String#singularize

複数形から単数形に変換

irb(main):015:0> ["phones", "wolves", "fish", "classes"].map(&:singularize)
=> ["phone", "wolf", "fish", "class"]

String#underscore

クラス名からファイル名に変換

irb(main):016:0> "ActiveRecord::Base".underscore
=> "active_record/base"

String#camelize

ファイル名からクラス名に変換

irb(main):017:0> "active_record/base".camelize
=> "ActiveRecord::Base"

String#classify

テーブル名からクラス名に変換

irb(main):006:0> ['people', 'wolves'].map(&:classify)
=> ["Person", "Wolf"]

String#tableize

クラス名からテーブル名に変換

irb(main):007:0> ["Person", "Wolf"].map(&:tableize)
=> ["people", "wolves"]
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away