Class: Zeitwerk::Inflector
- Inherits:
-
Object
- Object
- Zeitwerk::Inflector
- Defined in:
- lib/zeitwerk/inflector.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#camelize(basename, _abspath) ⇒ Object
Very basic snake case -> camel case conversion.
-
#inflect(inflections) ⇒ Object
Configures hard-coded inflections:.
Instance Method Details
#camelize(basename, _abspath) ⇒ Object
Very basic snake case -> camel case conversion.
inflector = Zeitwerk::Inflector.new
inflector.camelize("post", ...) # => "Post"
inflector.camelize("users_controller", ...) # => "UsersController"
inflector.camelize("api", ...) # => "Api"
Takes into account hard-coded mappings configured with ‘inflect`.
15 16 17 |
# File 'lib/zeitwerk/inflector.rb', line 15 def camelize(basename, _abspath) overrides[basename] || basename.split('_').each(&:capitalize!).join end |
#inflect(inflections) ⇒ Object
Configures hard-coded inflections:
inflector = Zeitwerk::Inflector.new
inflector.inflect(
"html_parser" => "HTMLParser",
"mysql_adapter" => "MySQLAdapter"
)
inflector.camelize("html_parser", abspath) # => "HTMLParser"
inflector.camelize("mysql_adapter", abspath) # => "MySQLAdapter"
inflector.camelize("users_controller", abspath) # => "UsersController"
32 33 34 |
# File 'lib/zeitwerk/inflector.rb', line 32 def inflect(inflections) overrides.merge!(inflections) end |