Last active
October 26, 2017 12:57
-
-
Save kelvinst/eb7373feaa57451cf94094099cbc2f55 to your computer and use it in GitHub Desktop.
How to override Kernel functionality on Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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