ExUtils.Modules (ExUtils v1.0.1)

Copy Markdown View Source

Generic Elixir utility methods for modules themselves

Summary

Functions

Check if a module exists and is compiled

Returns a Keyword List of all functions of a module.

Checks if a Module exports a specific function.

Returns a String of the Module's name (without the Elixir namespace)

Functions

exists?(module)

@spec exists?(module()) :: boolean()

Check if a module exists and is compiled

Example

iex> ExUtils.Modules.exists?(Map)
true
iex> ExUtils.Modules.exists?(NonExistentModule)
false

functions(module)

@spec functions(module()) :: Keyword.t()

Returns a Keyword List of all functions of a module.

Calling this will return a {:atom, arity} keyword list of all the functions of that module.

Example

iex> {:flatten, 1} in ExUtils.Modules.functions(List)
true
iex> {:unknown, 2} in ExUtils.Modules.functions(List)
false

has_function?(module, name)

@spec has_function?(module(), atom() | {atom(), non_neg_integer()}) :: boolean()

Checks if a Module exports a specific function.

First argument must be a Module and the second argument can either be an :atom name of the function or a {:atom, arity} tuple.

Example

iex> ExUtils.Modules.has_function?(Map, :keys)
true
iex> ExUtils.Modules.has_function?(Map, {:keys, 1})
true
iex> ExUtils.Modules.has_function?(Map, {:keys, 2})
false

has_method?(module, function)

This function is deprecated. Use ExUtils.Modules.has_function?/2 instead.

See ExUtils.Modules.has_function?/2.

methods(module)

This function is deprecated. Use ExUtils.Modules.functions/1 instead.

See ExUtils.Modules.functions/1.

name(module)

@spec name(module()) :: String.t()

Returns a String of the Module's name (without the Elixir namespace)

Example

iex> ExUtils.Modules.name(SomeModule)
"SomeModule"
iex> ExUtils.Modules.name(Another.Module)
"Another.Module"