Skip to content

Instantly share code, notes, and snippets.

@kelvinst
Last active October 26, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelvinst/eb7373feaa57451cf94094099cbc2f55 to your computer and use it in GitHub Desktop.
Save kelvinst/eb7373feaa57451cf94094099cbc2f55 to your computer and use it in GitHub Desktop.
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