You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/autoloading_and_reloading_constants.md
+15-11Lines changed: 15 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -274,38 +274,42 @@ By default, Rails uses `String#camelize` to know which constant should a given f
274
274
275
275
It could be the case that some particular file or directory name does not get inflected as you want. For instance, `html_parser.rb` is expected to define `HtmlParser` by default. What if you prefer the class to be `HTMLParser`? There are a few ways to customize this.
276
276
277
-
The easiest way is to define an acronym in `config/initializers/inflections.rb`:
277
+
The easiest way is to define acronyms in `config/initializers/inflections.rb`:
278
278
279
279
```ruby
280
280
ActiveSupport::Inflector.inflections(:en) do |inflect|
281
-
inflect.acronym 'HTML'
281
+
inflect.acronym "HTML"
282
+
inflect.acronym "SSL"
282
283
end
283
284
```
284
285
285
-
Doing so affects how Active Support inflects globally. That may be fine in some applications, but perhaps you prefer a more controlled technique that does not have a global effect. In such case, you can override the actual inflector in an initializer:
286
+
Doing so affects how Active Support inflects globally. That may be fine in some applications, but you can also customize how to camelize individual basenames independently from Active Support by passing a collection of overrides to the default inflectors:
As you see, that still uses `String#camelize`as fallback. If you instead prefer not to depend on Active Support inflections at all and have absolute control over inflections, do this instead:
298
+
That technique still depends on `String#camelize`, though, because that is what the default inflectors use as fallback. If you instead prefer not to depend on Active Support inflections at all and have absolute control over inflections, configure the inflectors to be instances of `Zeitwerk::Inflector`:
There is no global configuration that can affect said instances, they are deterministic.
312
+
309
313
You can even define a custom inflector for full flexibility. Please, check the [Zeitwerk documentation](https://github.com/fxn/zeitwerk#custom-inflector) for further details.
0 commit comments