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)?
__MODULE__ is a compilation environment macros which is the current module name as an atom. Now you know alias __MODULE__ just defines an alias for our Elixir module. This is very useful when used with defstruct which we will talk about next. In the following example, we pass API.
This is the pipe operator. From the linked docs: This operator introduces the expression on the left-hand side as the first argument to the function call on the right-hand side. Examples.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With