Class: Zeitwerk::Inflector
- Inherits:
-
Object
- Object
- Zeitwerk::Inflector
- Defined in:
- lib/zeitwerk/inflector.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#camelize(basename, _abspath) ⇒ String
Very basic snake case -> camel case conversion.
-
#inflect(inflections) ⇒ void
Configures hard-coded inflections:.
Instance Method Details
#camelize(basename, _abspath) ⇒ String
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`.
17 18 19 |
# File 'lib/zeitwerk/inflector.rb', line 17 def camelize(basename, _abspath) overrides[basename] || basename.split('_').map!(&:capitalize).join end |
#inflect(inflections) ⇒ void
This method returns an undefined value.
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"
35 36 37 |
# File 'lib/zeitwerk/inflector.rb', line 35 def inflect(inflections) overrides.merge!(inflections) end |