A short and quick intro to IEx
Intro
IEx is an interactive terminal for elixir lang. It is similar to irb for ruby and artisan for laravel.
To start IEx, type Iex on the command line.
Use IEx to quickly test code or prototype. In the example below we have defined a module MathFun with a function add. Notice we defined the module inside the IEx session. Most of the time however you will be calling modules defined inside your application
command completion
Command completion is one of the features available out of the box in elixir. Start IEx, type ‘h En’ and press tab, IEx completes the command, you should now see ‘Enum’, press tab again and Iex displays ‘Enum’ and ‘Enumerable’.
To see all the functions that are available in Enum module type “h Enum.”
Note the period after Enum
helpers
IEx provides helpers to make coding easier. We have already seen ‘h’ helper in action here are a few more options
i - find details about a structure of a variable.
r - reload a file
Suppose we have a single file CustData that has changed we can ask IEx to reload just this file by using the “r” function
iex>r CustData
viewing documentation
Say you have a module KV and you want to see the module docs for this module inside IEx
iex> h KV
To see documentation for a specific function, say “sum”
iex> h KV.sum
exiting IEx
To exit Iex you can either of the following
- press Ctrl C, twice
- Ctrl + \