In Elixir, is there any way to get a module to list its functions

elixir

In the same way that we can get any object (or class) in Ruby to list its methods, is there any function in Elixir to list all functions belonging to a module? Something (at least remotely) like String.functions (where String could be replaced by any other module name)?

Best Solution

Each module in Elixir defines an __info__ function you can call to get information about that module.

According the Elixir Docs, 1.6.6 e.g., you can pass it :functions to get a list of functions that module contains.

Map.__info__(:functions)

[delete: 2, drop: 2, equal?: 2, fetch: 2, fetch!: 2, from_struct: 1, get: 2,
 get: 3, has_key?: 2, keys: 1, merge: 2, merge: 3, new: 0, pop: 2, pop: 3,
 put: 3, put_new: 3, size: 1, split: 2, take: 2, to_list: 1, update: 4,
 update!: 3, values: 1]
Related Question