Skip to content

Commit 065b7f3

Browse files
committed
Document super and add more docs to defoverridable
1 parent 6004a36 commit 065b7f3

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,13 +1379,13 @@ defmodule Kernel do
13791379
file_info = FileInfo.new(atime: now())
13801380
file_info.atime #=> Returns the value of atime
13811381
file_info.atime(now()) #=> Updates the value of atime
1382-
1382+
13831383
# Update multiple attributes at once:
13841384
file_info.update(atime: now(), accesses: 1)
1385-
1385+
13861386
# Obtain the keywords representation of a record:
13871387
file_info.to_keywords #=> [accesses: 1, atime: {1370,7171,911705}]
1388-
1388+
13891389
13901390
A record is simply a tuple where the first element is the record
13911391
module name. We can get the record raw representation as follow:
@@ -1835,9 +1835,34 @@ defmodule Kernel do
18351835
end
18361836
18371837
@doc """
1838-
Makes the given functions in the current module overridable.
1839-
An overridable function is lazily defined, allowing a
1840-
developer to customize it.
1838+
Makes the given functions in the current module overridable. An overridable
1839+
function is lazily defined, allowing a developer to customize it.
1840+
1841+
## Example
1842+
1843+
defmodule DefaultMod do
1844+
defmacro __using__(_opts) do
1845+
quote do
1846+
def test(x, y) do
1847+
x + y
1848+
end
1849+
1850+
defoverridable [test: 2]
1851+
end
1852+
end
1853+
end
1854+
1855+
defmodule InheritMod do
1856+
use DefaultMod
1857+
1858+
def test(x, y) do
1859+
x * y + super
1860+
end
1861+
end
1862+
1863+
As seen as in the example `super` can be used to call the default
1864+
implementation, if no arguments are given to `super` it will be implictly
1865+
given the arguments of the current function.
18411866
"""
18421867
defmacro defoverridable(tuples) do
18431868
quote do

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Kernel.SpecialForms do
2424
2525
## Examples
2626
27-
:{}.(1,2,3)
27+
iex> { 1, 2, 3 }
2828
{ 1, 2, 3 }
2929
3030
"""
@@ -35,7 +35,7 @@ defmodule Kernel.SpecialForms do
3535
3636
## Examples
3737
38-
:[].(1,2,3)
38+
iex> [ 1, 2, 3 ]
3939
[ 1, 2, 3 ]
4040
4141
"""
@@ -810,4 +810,12 @@ defmodule Kernel.SpecialForms do
810810
811811
"""
812812
defmacro __aliases__(args)
813+
814+
@doc """
815+
Calls the overriden function when overriding it with `defoverridable`. If no
816+
arguments are given to `super` the overriden function will be called with the
817+
same arguments as the current one. See `Kernel.defoverridable` for more
818+
information and documentation.
819+
"""
820+
defmacro super(args)
813821
end

lib/elixir/lib/module.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ defmodule Module do
362362
@doc """
363363
Makes the given functions in the given module overridable.
364364
An overridable function is lazily defined, allowing a
365-
developer to customize it.
365+
developer to customize it. See `Kernel.defoverridable` for
366+
more information and documentation.
366367
"""
367368
def make_overridable(module, tuples) do
368369
assert_not_compiled!(:make_overridable, module)

0 commit comments

Comments
 (0)