module String::Inflections
def self.clear(scope = :all)
clear :all
Examples:
the options are: :plurals, :singulars, :uncountables
Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type,
def self.clear(scope = :all) case scope when :all @plurals, @singulars, @uncountables = [], [], [] else instance_variable_set("@#{scope}", []) end end
def self.irregular(singular, plural)
irregular 'octopus', 'octopi'
Examples:
for strings, not regular expressions. You simply pass the irregular in singular and plural form.
Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
def self.irregular(singular, plural) plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) end
def self.plural(rule, replacement)
Example:
The replacement should always be a string that may include references to the matched data from the rule.
Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
def self.plural(rule, replacement) @plurals.insert(0, [rule, replacement]) end
def self.singular(rule, replacement)
Example:
The replacement should always be a string that may include references to the matched data from the rule.
Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
def self.singular(rule, replacement) @singulars.insert(0, [rule, replacement]) end
def self.uncountable(*words)
uncountable "money", "information"
uncountable "money"
Examples:
Add uncountable words that shouldn't be attempted inflected.
def self.uncountable(*words) (@uncountables << words).flatten! end