How to get a list of available methods for my variable?

name = "poo"

How can i get the number of methods on the String data type on iex .

Like in ruby , name.methods?

You have to change your mindset, as you don’t have here any objects and classes. To check the functions (not methods anymore) of the String, you should so something like this:


which returns you all the functions that are exposed for the usage (in Elixir world we have by default exposed functions, but in Erlang you have to export them explicitly, so that’s why the function accept such atom as argument).

To examine what type of the variable you have, it’s more tricky. You can always use i or :slight_smile:


Also just to stress the point, there are no methods in Elixir - methods are in OOP languages. In Elixir/functional languages we have functions :slight_smile:


On IEx you can do:

exports String

It will show them nicely formatted and properly handle macros vs functions.


Calling twice exports Atom returns different values.
A reminder that Module’s names are Atoms.

$ iex -S mix
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.6.0) - press Ctrl+C to exit (type h() ENTER for help)
 iex(1)> exports Atom
__info__/1         to_char_list/1     to_charlist/1      to_string/1        module_info/0
 iex(2)> exports Atom
 to_char_list/1     to_charlist/1      to_string/1
1 Like