Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to override Kernel functionality on Elixir
defmodule MyKernel do
def a + b, do: a * b
end
defmodule UsingIt do
import Kernel, except: [+: 2]
import MyKernel
def foo, do: IO.puts("Result is #{1 + 2}")
end
$ iex -r override_kernel.exs
Erlang/OTP 20 [erts-9.1.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> UsingIt.foo()
Result is 2
:ok
iex(2)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.