Skip to content

Adding helper to reload elixir modules while in iex. #2

Open
wants to merge 1 commit into from

2 participants

@khia
khia commented Jul 20, 2012

Typical usage scenario is like follows:

    iex(1)> use Reload
    []
    iex(2)> reload [My.Awesome.Elixir.Module]
    [{:module,My.Awesome.Elixir.Module}]
@yrashk yrashk commented on the diff Jul 20, 2012
lib/reload.ex
+
+ @doc """
+ This function simplifies experimenting in elixir shell.
+ Typical usage scenario is like follows:
+ iex(1)> use Reload
+ []
+ iex(2)> reload [My.Awesome.Elixir.Module]
+ [{:module,My.Awesome.Elixir.Module}]
+ """
+ def reload(modules) when is_list(modules) do
+ lc module inlist modules, do: reload(module)
+ end
+ def reload(module) do
+ :code.delete(module)
+ :code.purge(module)
+ :code.load_file(module)
@yrashk
Owner
yrashk added a note Jul 20, 2012

shouldn't this be ensure_loaded instead?

@khia
khia added a note Jul 23, 2012

What do you mean:
1. reload should be renamed into ensure_loaded. It shouldn't since reload also do purge so semantically it's more reload rather than ensure.
2. Instead :code.load_file we should use unsure_loaded. In this case regular erlang modules couldn't be reloaded. Since internally module is represented as atom with __MAIN__ prefix erlang means of reloading works just fine.
3. Instead of reload the one could use ensure_loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.