Module Inflector
In: vendor/rails/activesupport/lib/active_support/inflector.rb

The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without, and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept in inflections.rb.

Methods

Classes and Modules

Class Inflector::Inflections

Public Instance methods

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 112
112:   def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
113:     if first_letter_in_uppercase
114:       lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
115:     else
116:       lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
117:     end
118:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 148
148:   def classify(table_name)
149:     # strip out any leading schema name
150:     camelize(singularize(table_name.to_s.sub(/.*\./, '')))
151:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 157
157:   def constantize(camel_cased_word)
158:     raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!" unless
159:       /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ camel_cased_word
160:     
161:     camel_cased_word = "::#{camel_cased_word}" unless $1
162:     Object.module_eval(camel_cased_word, __FILE__, __LINE__)
163:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 132
132:   def dasherize(underscored_word)
133:     underscored_word.gsub(/_/, '-')
134:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 140
140:   def demodulize(class_name_in_module)
141:     class_name_in_module.to_s.gsub(/^.*::/, '')
142:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 153
153:   def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
154:     underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
155:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 136
136:   def humanize(lower_case_and_underscored_word)
137:     lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
138:   end

[Source]

    # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 82
82:   def inflections
83:     if block_given?
84:       yield Inflections.instance
85:     else
86:       Inflections.instance
87:     end
88:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 165
165:   def ordinalize(number)
166:     if (11..13).include?(number.to_i % 100)
167:       "#{number}th"
168:     else
169:       case number.to_i % 10
170:         when 1: "#{number}st"
171:         when 2: "#{number}nd"
172:         when 3: "#{number}rd"
173:         else    "#{number}th"
174:       end
175:     end
176:   end

[Source]

    # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 90
90:   def pluralize(word)
91:     result = word.to_s.dup
92: 
93:     if inflections.uncountables.include?(result.downcase)
94:       result
95:     else
96:       inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
97:       result
98:     end
99:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 101
101:   def singularize(word)
102:     result = word.to_s.dup
103: 
104:     if inflections.uncountables.include?(result.downcase)
105:       result
106:     else
107:       inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
108:       result
109:     end
110:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 144
144:   def tableize(class_name)
145:     pluralize(underscore(class_name))
146:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 120
120:   def titleize(word)
121:     humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
122:   end

[Source]

     # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 124
124:   def underscore(camel_cased_word)
125:     camel_cased_word.to_s.gsub(/::/, '/').
126:       gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
127:       gsub(/([a-z\d])([A-Z])/,'\1_\2').
128:       tr("-", "_").
129:       downcase
130:   end

[Validate]