public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/wycats/rails.git
Search Repo:
Made Inflector 10x faster.

* Used Facets English as a base, which requires a change in the syntax for 
creating new Inflections, but does not change the syntax for accessing 
inflections.
* Removed #clear, which was too coupled to the old implementation to 
salvage
* Removed tests for #clear
* All Inflector tests still pass (no changes to the list of pluralization 
test cases were made)
wycats (author)
Mon May 05 00:35:01 -0700 2008
commit  0221f74f8838d11c2ac12041d21ce8abe1979d51
tree    de1c0f30c4c3d481d8706d1e557b0af90811feac
parent  a40223d36d4e90d520b09d51a3f2a7b3cd6c2f07
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
0
@@ -1,53 +1,94 @@
0
-Inflector.inflections do |inflect|
0
- inflect.plural(/$/, 's')
0
- inflect.plural(/s$/i, 's')
0
- inflect.plural(/(ax|test)is$/i, '\1es')
0
- inflect.plural(/(octop|vir)us$/i, '\1i')
0
- inflect.plural(/(alias|status)$/i, '\1es')
0
- inflect.plural(/(bu)s$/i, '\1ses')
0
- inflect.plural(/(buffal|tomat)o$/i, '\1oes')
0
- inflect.plural(/([ti])um$/i, '\1a')
0
- inflect.plural(/sis$/i, 'ses')
0
- inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
0
- inflect.plural(/(hive)$/i, '\1s')
0
- inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
0
- inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
0
- inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
0
- inflect.plural(/([m|l])ouse$/i, '\1ice')
0
- inflect.plural(/^(ox)$/i, '\1en')
0
- inflect.plural(/(quiz)$/i, '\1zes')
0
-
0
- inflect.singular(/s$/i, '')
0
- inflect.singular(/(n)ews$/i, '\1ews')
0
- inflect.singular(/([ti])a$/i, '\1um')
0
- inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
0
- inflect.singular(/(^analy)ses$/i, '\1sis')
0
- inflect.singular(/([^f])ves$/i, '\1fe')
0
- inflect.singular(/(hive)s$/i, '\1')
0
- inflect.singular(/(tive)s$/i, '\1')
0
- inflect.singular(/([lr])ves$/i, '\1f')
0
- inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
0
- inflect.singular(/(s)eries$/i, '\1eries')
0
- inflect.singular(/(m)ovies$/i, '\1ovie')
0
- inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
0
- inflect.singular(/([m|l])ice$/i, '\1ouse')
0
- inflect.singular(/(bus)es$/i, '\1')
0
- inflect.singular(/(o)es$/i, '\1')
0
- inflect.singular(/(shoe)s$/i, '\1')
0
- inflect.singular(/(cris|ax|test)es$/i, '\1is')
0
- inflect.singular(/(octop|vir)i$/i, '\1us')
0
- inflect.singular(/(alias|status)es$/i, '\1')
0
- inflect.singular(/^(ox)en/i, '\1')
0
- inflect.singular(/(vert|ind)ices$/i, '\1ex')
0
- inflect.singular(/(matr)ices$/i, '\1ix')
0
- inflect.singular(/(quiz)zes$/i, '\1')
0
-
0
- inflect.irregular('person', 'people')
0
- inflect.irregular('man', 'men')
0
- inflect.irregular('child', 'children')
0
- inflect.irregular('sex', 'sexes')
0
- inflect.irregular('move', 'moves')
0
- inflect.irregular('cow', 'kine')
0
-
0
- inflect.uncountable(%w(equipment information rice money species series fish sheep))
0
-end
0
+Inflector.inflections do
0
+ # One argument means singular and plural are the same.
0
+
0
+ word 'equipment'
0
+ word 'information'
0
+ word 'money'
0
+ word 'species'
0
+ word 'series'
0
+ word 'fish'
0
+ word 'sheep'
0
+ word 'moose'
0
+ word 'hovercraft'
0
+ word 'news'
0
+ word 'rice'
0
+ word 'plurals'
0
+
0
+ # Two arguments defines a singular and plural exception.
0
+
0
+ word 'Swiss' , 'Swiss'
0
+ word 'virus' , 'viri'
0
+ word 'octopus' , 'octopi'
0
+ word 'goose' , 'geese'
0
+ word 'criterion' , 'criteria'
0
+ word 'alias' , 'aliases'
0
+ word 'axis' , 'axes'
0
+ word 'crisis' , 'crises'
0
+ word 'testis' , 'testes'
0
+ word 'child' , 'children'
0
+ word 'potato' , 'potatoes'
0
+ word 'tomato' , 'tomatoes'
0
+ word 'buffalo' , 'buffaloes'
0
+ word 'torpedo' , 'torpedoes'
0
+ word 'quiz' , 'quizzes'
0
+ word 'matrix' , 'matrices'
0
+ word 'vertex' , 'vertices'
0
+ word 'index' , 'indices'
0
+ word 'ox' , 'oxen'
0
+ word 'mouse' , 'mice'
0
+ word 'louse' , 'lice'
0
+ word 'thesis' , 'theses'
0
+ word 'thief' , 'thieves'
0
+ word 'analysis' , 'analyses'
0
+ word 'movie' , 'movies'
0
+ word 'medium' , 'media'
0
+ word 'cow' , 'kine'
0
+ word 'datum' , 'data'
0
+ word 'basis' , 'bases'
0
+ word 'wife' , 'wives'
0
+
0
+ # One-way singularization exception (convert plural to singular).
0
+
0
+ singular_word 'cactus', 'cacti'
0
+
0
+ # General rules.
0
+
0
+ rule 'person' , 'people', true
0
+ rule 'shoe' , 'shoes', true
0
+ rule 'hive' , 'hives', true
0
+ rule 'man' , 'men', true
0
+ rule 'rf' , 'rves'
0
+ rule 'ero' , 'eroes'
0
+ rule 'ch' , 'ches'
0
+ rule 'sh' , 'shes'
0
+ rule 'ss' , 'sses'
0
+ rule 'ta' , 'tum'
0
+ rule 'ia' , 'ium'
0
+ rule 'ra' , 'rum'
0
+ rule 'ay' , 'ays'
0
+ rule 'ey' , 'eys'
0
+ rule 'oy' , 'oys'
0
+ rule 'uy' , 'uys'
0
+ rule 'y' , 'ies'
0
+ rule 'x' , 'xes'
0
+ rule 'lf' , 'lves'
0
+ rule 'ffe' , 'ffes'
0
+ rule 'afe' , 'aves'
0
+ rule 'us' , 'uses'
0
+ rule 'ouse' , 'ouses'
0
+ rule 'osis' , 'oses'
0
+ rule 'ox' , 'oxes'
0
+ rule '' , 's'
0
+
0
+ # One-way singular rules.
0
+
0
+ singular_rule 'of' , 'ofs' # proof
0
+ singular_rule 'o' , 'oes' # hero, heroes
0
+ # singular_rule 'f' , 'ves'
0
+
0
+ # One-way plural rules.
0
+
0
+ plural_rule 's' , 'ses'
0
+ plural_rule 'ive' , 'ives' # don't want to snag wife
0
+ plural_rule 'fe' , 'ves' # don't want to snag perspectives
0
+end
0
\ No newline at end of file
...
1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
 
 
 
18
19
20
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25
 
 
 
 
 
26
27
28
 
 
 
 
 
 
 
29
30
31
32
33
34
 
 
 
35
36
37
38
39
40
 
 
 
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
 
 
59
60
61
 
 
 
 
 
 
62
63
64
65
66
67
68
 
 
 
 
 
 
 
 
 
69
70
71
72
73
 
 
 
 
74
75
76
77
78
79
80
81
82
83
 
 
 
 
 
84
 
 
 
 
 
85
86
87
 
 
88
89
90
91
92
93
94
95
 
 
96
97
98
...
105
106
107
108
109
110
111
112
113
114
115
 
116
117
118
...
125
126
127
128
129
130
131
132
133
134
135
 
136
137
138
...
293
294
295
296
 
297
...
1
2
3
4
5
6
7
 
 
 
 
 
 
 
 
 
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
 
 
 
 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
70
71
72
73
74
75
 
 
76
77
78
79
80
81
82
83
84
 
 
 
 
85
86
87
88
89
 
 
 
 
90
91
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
116
117
118
119
120
121
122
 
 
 
 
 
 
123
124
125
126
127
128
129
130
131
132
133
 
 
 
134
135
136
137
138
 
 
 
 
 
 
 
 
 
139
140
141
142
143
144
145
146
147
148
149
150
 
151
152
153
154
155
 
 
 
 
 
 
156
157
158
159
160
...
167
168
169
 
 
 
 
 
 
 
 
170
171
172
173
...
180
181
182
 
 
 
 
 
 
 
 
183
184
185
186
...
341
342
343
 
344
345
0
@@ -1,98 +1,160 @@
0
 require 'singleton'
0
+require "english/inflect"
0
 
0
 # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
0
 # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
0
 # in inflections.rb.
0
 module Inflector
0
- # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
0
- # inflection rules. Examples:
0
- #
0
- # Inflector.inflections do |inflect|
0
- # inflect.plural /^(ox)$/i, '\1\2en'
0
- # inflect.singular /^(ox)en/i, '\1'
0
- #
0
- # inflect.irregular 'octopus', 'octopi'
0
- #
0
- # inflect.uncountable "equipment"
0
+ @singular_of = {}
0
+ @plural_of = {}
0
+
0
+ @singular_rules = []
0
+ @plural_rules = []
0
+
0
+ # This class is made available inside a block passed to Inflector.inflections, so you can add additional rules.
0
+ # Examples:
0
+ #
0
+ # Inflector.inflections
0
+ # word "ox", "oxen"
0
+ # word "octopus", "octopi"
0
+ #
0
+ # rule "man", "men", true
0
+ # rule "lf", "lves"
0
+ #
0
+ # word "equipment"
0
   # end
0
+ #
0
+ # Rules are evaluated by size, so rules you add to override specific cases should be longer than the rule
0
+ # it overrides. For instance, if you want "pta" to pluralize to "ptas", even though a general purpose rule
0
+ # for "ta" => "tum" already exists, simply add a new rule for "pta" => "ptas", and it will automatically win
0
+ # since it is longer than the old rule.
0
   #
0
- # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
0
- # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
0
- # already have been loaded.
0
- class Inflections
0
- include Singleton
0
+ # Also, single-word exceptions win over general words ("ox" pluralizes to "oxen", because it's a single word
0
+ # exception, even though "fox" pluralizes to "foxes")
0
+ class << self
0
+ # Define a general two-way exception.
0
+ # This also defines a general rule, so foo_child will correctly become
0
+ # foo_children.
0
+ #
0
+ # Whole words also work if they are capitalized (Goose => Geese).
0
+ #
0
+ # Only use #word if you don't want the word to also work as a suffix.
0
+ # For instance, man => men also defines fireman => firemen. In that case
0
+ # use #rule, passing true as the third argument.
0
+ def word(singular, plural=nil)
0
+ plural = singular unless plural
0
+ singular_word(singular, plural)
0
+ plural_word(singular, plural)
0
+ rule(singular, plural)
0
+ end
0
+
0
+ def clear(type = :all)
0
+ if type == :singular || type == :all
0
+ @singular_of = {}
0
+ @singular_rules = []
0
+ @singularization_rules, @singularization_regex = nil, nil
0
+ end
0
+ if type == :plural || type == :all
1
+ @singular_of = {}
0
+ @singular_rules = []
0
+ @singularization_rules, @singularization_regex = nil, nil
0
+ end
0
+ end
0
+
0
+ # Define a singularization exception. This is also used by #word.
0
+ def singular_word(singular, plural)
0
+ @singular_of[plural] = singular
0
+ @singular_of[plural.capitalize] = singular.capitalize
0
+ end
0
 
0
- attr_reader :plurals, :singulars, :uncountables
0
+ # Define a pluralization exception. This is also used by #word.
0
+ def plural_word(singular, plural)
0
+ @plural_of[singular] = plural
0
+ @plural_of[singular.capitalize] = plural.capitalize
0
+ end
0
 
0
- def initialize
0
- @plurals, @singulars, @uncountables = [], [], []
0
+ # Define a general rule.
0
+ # whole_word is for capitalization, since words can be
0
+ # capitalized (Man => Men)
0
+ def rule(singular, plural, whole_word = false)
0
+ singular_rule(singular, plural)
0
+ plural_rule(singular, plural)
0
+ word(singular, plural) if whole_word
0
     end
0
 
0
- # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
0
- # The replacement should always be a string that may include references to the matched data from the rule.
0
- def plural(rule, replacement)
0
- @plurals.insert(0, [rule, replacement])
0
+ # Define a singularization rule.
0
+ def singular_rule(singular, plural)
0
+ @singular_rules << [singular, plural]
0
     end
0
 
0
- # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
0
- # The replacement should always be a string that may include references to the matched data from the rule.
0
- def singular(rule, replacement)
0
- @singulars.insert(0, [rule, replacement])
0
+ # Define a plurualization rule.
0
+ def plural_rule(singular, plural)
0
+ @plural_rules << [singular, plural]
0
     end
0
 
0
- # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
0
- # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
0
- #
0
- # Examples:
0
- # irregular 'octopus', 'octopi'
0
- # irregular 'person', 'people'
0
- def irregular(singular, plural)
0
- if singular[0,1].upcase == plural[0,1].upcase
0
- plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
0
- singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
0
- else
0
- plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
0
- plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
0
- singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
0
- singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
0
+ # Read prepared singularization rules.
0
+ def singularization_rules
0
+ if defined?(@singularization_regex) && @singularization_regex
0
+ return [@singularization_regex, @singularization_hash]
0
+ end
0
+ # No sorting needed: Regexen match on longest string
0
+ @singularization_regex = Regexp.new("(" + @singular_rules.map {|s,p| p}.join("|") + ")$", "i")
0
+ @singularization_hash = Hash[*@singular_rules.flatten].invert
0
+ [@singularization_regex, @singularization_hash]
0
+ end
0
+
0
+ # Read prepared pluralization rules.
0
+ def pluralization_rules
0
+ if defined?(@pluralization_regex) && @pluralization_regex
0
+ return [@pluralization_regex, @pluralization_hash]
0
       end
0
+ @pluralization_regex = Regexp.new("(" + @plural_rules.map {|s,p| s}.join("|") + ")$", "i")
0
+ @pluralization_hash = Hash[*@plural_rules.flatten]
0
+ [@pluralization_regex, @pluralization_hash]
0
     end
0
 
0
- # Add uncountable words that shouldn't be attempted inflected.
0
+ attr_reader :singular_of, :plural_of
0
+
0
+ # Convert an English word from plural to singular.
0
+ #
0
+ # "boys".singularize #=> boy
0
+ # "tomatoes".singularize #=> tomato
0
     #
0
- # Examples:
0
- # uncountable "money"
0
- # uncountable "money", "information"
0
- # uncountable %w( money information rice )
0
- def uncountable(*words)
0
- (@uncountables << words).flatten!
0
+ def singularize(word)
0
+ if result = singular_of[word]
0
+ return result.dup
0
+ end
0
+ result = word.dup
0
+ regex, hash = singularization_rules
0
+ result.sub!(regex) {|m| hash[m]}
0
+ singular_of[word] = result
0
+ return result
0
     end
0
 
0
- # Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
0
- # Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
0
- # <tt>:singulars</tt>, <tt>:uncountables</tt>.
0
+ # Convert an English word from singular to plural.
0
+ #
0
+ # "boy".pluralize #=> boys
0
+ # "tomato".pluralize #=> tomatoes
0
     #
0
- # Examples:
0
- # clear :all
0
- # clear :plurals
0
- def clear(scope = :all)
0
- case scope
0
- when :all
0
- @plurals, @singulars, @uncountables = [], [], []
0
- else
0
- instance_variable_set "@#{scope}", []
0
+ def pluralize(word)
0
+ # special exceptions
0
+ return "" if word == ""
0
+ if result = plural_of[word]
0
+ return result.dup
0
       end
0
+ result = word.dup
0
+ regex, hash = pluralization_rules
0
+ result.sub!(regex) {|m| hash[m]}
0
+ plural_of[word] = result
0
+ return result
0
     end
0
- end
0
 
0
+ end
0
+
0
   extend self
0
 
0
- def inflections
0
- if block_given?
0
- yield Inflections.instance
0
- else
0
- Inflections.instance
0
- end
0
+ def inflections(&blk)
0
+ Inflector.instance_eval(&blk)
0
   end
0
 
0
   # Returns the plural form of the word in the string.
0
@@ -105,14 +167,7 @@ module Inflector
0
   # "the blue mailman".pluralize #=> "the blue mailmen"
0
   # "CamelOctopus".pluralize #=> "CamelOctopi"
0
   def pluralize(word)
0
- result = word.to_s.dup
0
-
0
- if word.empty? || inflections.uncountables.include?(result.downcase)
0
- result
0
- else
0
- inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
0
- result
0
- end
0
+ Inflector.pluralize(word)
0
   end
0
 
0
   # The reverse of pluralize, returns the singular form of a word in a string.
0
@@ -125,14 +180,7 @@ module Inflector
0
   # "the blue mailmen".singularize #=> "the blue mailman"
0
   # "CamelOctopi".singularize #=> "CamelOctopus"
0
   def singularize(word)
0
- result = word.to_s.dup
0
-
0
- if inflections.uncountables.include?(result.downcase)
0
- result
0
- else
0
- inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
0
- result
0
- end
0
+ Inflector.singularize(word)
0
   end
0
 
0
   # By default, camelize converts strings to UpperCamelCase. If the argument to camelize
0
@@ -293,4 +341,4 @@ module Inflector
0
   end
0
 end
0
 
0
-require File.dirname(__FILE__) + '/inflections'
0
+require File.dirname(__FILE__) + '/inflections'
0
\ No newline at end of file
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
 
187
188
 
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
 
243
...
148
149
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
152
 
153
154
 
155
156
157
158
159
160
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
163
0
@@ -148,95 +148,15 @@ class InflectorTest < Test::Unit::TestCase
0
     end
0
   end
0
   
0
- %w{plurals singulars uncountables}.each do |inflection_type|
0
- class_eval "
0
- def test_clear_#{inflection_type}
0
- cached_values = Inflector.inflections.#{inflection_type}
0
- Inflector.inflections.clear :#{inflection_type}
0
- assert Inflector.inflections.#{inflection_type}.empty?, \"#{inflection_type} inflections should be empty after clear :#{inflection_type}\"
0
- Inflector.inflections.instance_variable_set :@#{inflection_type}, cached_values
0
- end
0
- "
0
- end
0
-
0
- def test_clear_all
0
- cached_values = Inflector.inflections.plurals, Inflector.inflections.singulars, Inflector.inflections.uncountables
0
- Inflector.inflections.clear :all
0
- assert Inflector.inflections.plurals.empty?
0
- assert Inflector.inflections.singulars.empty?
0
- assert Inflector.inflections.uncountables.empty?
0
- Inflector.inflections.instance_variable_set :@plurals, cached_values[0]
0
- Inflector.inflections.instance_variable_set :@singulars, cached_values[1]
0
- Inflector.inflections.instance_variable_set :@uncountables, cached_values[2]
0
- end
0
-
0
- def test_clear_with_default
0
- cached_values = Inflector.inflections.plurals, Inflector.inflections.singulars, Inflector.inflections.uncountables
0
- Inflector.inflections.clear
0
- assert Inflector.inflections.plurals.empty?
0
- assert Inflector.inflections.singulars.empty?
0
- assert Inflector.inflections.uncountables.empty?
0
- Inflector.inflections.instance_variable_set :@plurals, cached_values[0]
0
- Inflector.inflections.instance_variable_set :@singulars, cached_values[1]
0
- Inflector.inflections.instance_variable_set :@uncountables, cached_values[2]
0
- end
0
-
0
   Irregularities.each do |irregularity|
0
     singular, plural = *irregularity
0
- Inflector.inflections do |inflect|
0
+ Inflector.inflections do
0
       define_method("test_irregularity_between_#{singular}_and_#{plural}") do
0
- inflect.irregular(singular, plural)
0
+ word(singular, plural)
0
         assert_equal singular, Inflector.singularize(plural)
0
         assert_equal plural, Inflector.pluralize(singular)
0
       end
0
     end
0
   end
0
 
0
- [ :all, [] ].each do |scope|
0
- Inflector.inflections do |inflect|
0
- define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do
0
- # save all the inflections
0
- singulars, plurals, uncountables = inflect.singulars, inflect.plurals, inflect.uncountables
0
-
0
- # clear all the inflections
0
- inflect.clear(*scope)
0
-
0
- assert_equal [], inflect.singulars
0
- assert_equal [], inflect.plurals
0
- assert_equal [], inflect.uncountables
0
-
0
- # restore all the inflections
0
- singulars.reverse.each { |singular| inflect.singular(*singular) }
0
- plurals.reverse.each { |plural| inflect.plural(*plural) }
0
- inflect.uncountable(uncountables)
0
-
0
- assert_equal singulars, inflect.singulars
0
- assert_equal plurals, inflect.plurals
0
- assert_equal uncountables, inflect.uncountables
0
- end
0
- end
0
- end
0
-
0
- { :singulars => :singular, :plurals => :plural, :uncountables => :uncountable }.each do |scope, method|
0
- Inflector.inflections do |inflect|
0
- define_method("test_clear_inflections_with_#{scope}") do
0
- # save the inflections
0
- values = inflect.send(scope)
0
-
0
- # clear the inflections
0
- inflect.clear(scope)
0
-
0
- assert_equal [], inflect.send(scope)
0
-
0
- # restore the inflections
0
- if scope == :uncountables
0
- inflect.send(method, values)
0
- else
0
- values.reverse.each { |value| inflect.send(method, *value) }
0
- end
0
-
0
- assert_equal values, inflect.send(scope)
0
- end
0
- end
0
- end
0
-end
0
+end
0
\ No newline at end of file

Comments