Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/reload.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Reload do
defmacro __using__(_) do
quote do
import Reload
end
end

@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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be ensure_loaded instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

end
end