Elixir: How could I convert a binary to a Captial atom

Created on 28 Apr 2014  路  5Comments  路  Source: elixir-lang/elixir

Is't there any functions to convert a binary to a Capital atom, the binary_to_atom/1 just convert add a : before the binary part. Is it possible for me to convert a binary like "Binary" to Binary, and not the :Binary?

And I have another question, Is it convenience when the atom :Binary matches atom Binary

Most helpful comment

Yeah, Module.split and Module.concat may be a huge help here.

All 5 comments

Hi, you can use the forums to ask questions: https://groups.google.com/forum/#!forum/elixir-lang-talk

I think you want the Elixir prefix. Not sure why you would need to do this thought.

iex(1)> binary_to_atom "Elixir.Foo"
Foo

To convert to just a capitalized atom, you can do: String.capitalize(binary) |> binary_to_atom.

@pma, this works, thanks. I want to pick out some Modules from a given module name in binary format, so I want to convert the given binary name to atom, and then comparing

Module.concat/1 is used for this. It takes a list of atoms or binaries and returns a module name.

Yeah, Module.split and Module.concat may be a huge help here.

Was this page helpful?
0 / 5 - 0 ratings