A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional inflection rules. Examples:
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /^(ox)$/i, '\1\2en'
inflect.singular /^(ox)en/i, '\1'
inflect.irregular 'octopus', 'octopi'
inflect.uncountable "equipment"
end
New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may already have been loaded.
Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type, the options are: :plurals, :singulars, :uncountables, :humans.
Examples:
clear :all clear :plurals
# File lib/active_support/inflector/inflections.rb, line 96
96: def clear(scope = :all)
97: case scope
98: when :all
99: @plurals, @singulars, @uncountables = [], [], []
100: else
101: instance_variable_set "@#{scope}", []
102: end
103: end
Specifies a humanized form of a string by a regular expression rule or by a string mapping. When using a regular expression based replacement, the normal humanize formatting is called after the replacement. When a string is used, the human form should be specified as desired (example: ‘The name’, not ‘the_name’)
Examples:
human /_cnt$/i, '\1_count' human "legacy_col_person_name", "Name"
# File lib/active_support/inflector/inflections.rb, line 85
85: def human(rule, replacement)
86: @humans.insert(0, [rule, replacement])
87: end
Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used for strings, not regular expressions. You simply pass the irregular in singular and plural form.
Examples:
irregular 'octopus', 'octopi' irregular 'person', 'people'
# File lib/active_support/inflector/inflections.rb, line 51
51: def irregular(singular, plural)
52: @uncountables.delete(singular)
53: @uncountables.delete(plural)
54: if singular[0,1].upcase == plural[0,1].upcase
55: plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..1])
56: plural(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + plural[1..1])
57: singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..1])
58: else
59: plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..1])
60: plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..1])
61: plural(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), plural[0,1].upcase + plural[1..1])
62: plural(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), plural[0,1].downcase + plural[1..1])
63: singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..1])
64: singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..1])
65: end
66: end
Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression. The replacement should always be a string that may include references to the matched data from the rule.
# File lib/active_support/inflector/inflections.rb, line 31
31: def plural(rule, replacement)
32: @uncountables.delete(rule) if rule.is_a?(String)
33: @uncountables.delete(replacement)
34: @plurals.insert(0, [rule, replacement])
35: end
Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression. The replacement should always be a string that may include references to the matched data from the rule.
# File lib/active_support/inflector/inflections.rb, line 39
39: def singular(rule, replacement)
40: @uncountables.delete(rule) if rule.is_a?(String)
41: @uncountables.delete(replacement)
42: @singulars.insert(0, [rule, replacement])
43: end
Add uncountable words that shouldn’t be attempted inflected.
Examples:
uncountable "money" uncountable "money", "information" uncountable %w( money information rice )
# File lib/active_support/inflector/inflections.rb, line 74
74: def uncountable(*words)
75: (@uncountables << words).flatten!
76: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.