CamelCase to underscore and back again w/Elixir
If you have a mix project name with multiple words, then those multiple words are generally separated with underscores in the project directory name, like honey_bears
. The module name for the project however is HoneyBears
.
Converting a string from underscore to CamelCase is built into Elixir. Its in the Macro
module:
> Macro.camelize("honey_bear")
"HoneyBear"
The reverse case also can be solved with a Macro
function.
> Macro.underscore("HoneyBear")
"honey_bear"
The Macro module has a number of convience functions for working with macros.
Tweet