Brian
Import a module from a file into IEX
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from . import xyz
xyz.do_something()
I did a bit of google and this is what I found
$ iex
Code.load_file(“some_file.exs”)
moduleFromSomeFile.doSomething(1)
I was wondering if this is the “right” way to import a module in to iex and just inspecting/playing around with functions.
Thank you
Most Liked
elderbas
If I’m just dinkin around in a directory, outside of a mix project, and I have a module named “SomeModule.exs” in the working directory and I’m in iex, I do
c "SomeModule.exs", and I’ll have the module available to play with.
OvermindDL1
If the compiled module is on the binary path for the BEAM then you can just do import Xyx to import everything from it. Or call it straight with Xyz.blah(42). mix sets up all those paths for you automatically if it is part of a project so with a mix project you can just do iex -S mix to get everything linked properly.
hauleth
$ iex -S mix
iex> Jason.encode!(%{"a" => 1})
"{\"a\":1}"







