mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Improve documentation to classify to make it clear that it expects names to be plural. Reference #10615 [kris_chambers]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8596 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
8f7fa55e8d
commit
96d3b7ced4
2 changed files with 10 additions and 4 deletions
|
@ -104,13 +104,16 @@ module ActiveSupport #:nodoc:
|
||||||
Inflector.tableize(self)
|
Inflector.tableize(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a class name from a table name like Rails does for table names to models.
|
# Create a class name from a plural table name like Rails does for table names to models.
|
||||||
# Note that this returns a string and not a Class. (To convert to an actual class
|
# Note that this returns a string and not a Class. (To convert to an actual class
|
||||||
# follow classify with constantize.)
|
# follow classify with constantize.)
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
# "egg_and_hams".classify #=> "EggAndHam"
|
# "egg_and_hams".classify #=> "EggAndHam"
|
||||||
# "post".classify #=> "Post"
|
# "posts".classify #=> "Post"
|
||||||
|
#
|
||||||
|
# Singular names are not handled correctly
|
||||||
|
# "business".classify #=> "Busines"
|
||||||
def classify
|
def classify
|
||||||
Inflector.classify(self)
|
Inflector.classify(self)
|
||||||
end
|
end
|
||||||
|
|
|
@ -218,13 +218,16 @@ module Inflector
|
||||||
pluralize(underscore(class_name))
|
pluralize(underscore(class_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a class name from a table name like Rails does for table names to models.
|
# Create a class name from a plural table name like Rails does for table names to models.
|
||||||
# Note that this returns a string and not a Class. (To convert to an actual class
|
# Note that this returns a string and not a Class. (To convert to an actual class
|
||||||
# follow classify with constantize.)
|
# follow classify with constantize.)
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
# "egg_and_hams".classify #=> "EggAndHam"
|
# "egg_and_hams".classify #=> "EggAndHam"
|
||||||
# "post".classify #=> "Post"
|
# "posts".classify #=> "Post"
|
||||||
|
#
|
||||||
|
# Singular names are not handled correctly
|
||||||
|
# "business".classify #=> "Busines"
|
||||||
def classify(table_name)
|
def classify(table_name)
|
||||||
# strip out any leading schema name
|
# strip out any leading schema name
|
||||||
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
|
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
|
||||||
|
|
Loading…
Reference in a new issue