Skip to content

Commit 97e70e6

Browse files
Igor KapkovJosé Valim
authored andcommitted
change some doc examples to iex style
1 parent 0883c75 commit 97e70e6

35 files changed

+358
-132
lines changed

lib/eex/lib/eex.ex

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ defmodule EEx do
55
EEx stands for Embedded Elixir. It allows you to embed
66
Elixir code inside a string in a robust way:
77
8-
EEx.eval_string "foo <%= bar %>", [bar: "baz"]
9-
#=> "foo baz"
8+
iex> EEx.eval_string "foo <%= bar %>", [bar: "baz"]
9+
"foo baz"
1010
1111
## API
1212
@@ -31,7 +31,7 @@ defmodule EEx do
3131
3232
All functions in this module accepts EEx-related options.
3333
They are:
34-
34+
3535
* `:line` - the line to be used as the template start.
3636
Defaults to 1;
3737
* `:file` - the file to be used in the template.
@@ -79,8 +79,8 @@ defmodule EEx do
7979
An example is the `@` macro which allows easy data access
8080
in a template:
8181
82-
EEx.eval_string "<%= @foo %>", assigns: [foo: 1]
83-
#=> 1
82+
iex> EEx.eval_string "<%= @foo %>", assigns: [foo: 1]
83+
"1"
8484
8585
In other words, <%= @foo %> is simply translated to:
8686
@@ -97,12 +97,12 @@ defmodule EEx do
9797
9898
## Examples
9999
100-
defmodule Sample do
101-
require EEx
102-
EEx.function_from_string :def, :sample, "<%= a + b %>", [:a, :b]
103-
end
104-
105-
Sample.sample(1, 2) #=> "3"
100+
iex> defmodule Sample do
101+
...> require EEx
102+
...> EEx.function_from_string :def, :sample, "<%= a + b %>", [:a, :b]
103+
...> end
104+
iex> Sample.sample(1, 2)
105+
"3"
106106
107107
"""
108108
defmacro function_from_string(kind, name, source, args \\ [], options \\ []) do
@@ -177,8 +177,8 @@ defmodule EEx do
177177
178178
## Examples
179179
180-
EEx.eval_string "foo <%= bar %>", [bar: "baz"]
181-
#=> "foo baz"
180+
iex> EEx.eval_string "foo <%= bar %>", [bar: "baz"]
181+
"foo baz"
182182
183183
"""
184184
def eval_string(source, bindings \\ [], options \\ []) do
@@ -195,8 +195,7 @@ defmodule EEx do
195195
foo <%= bar %>
196196
197197
# iex
198-
EEx.eval_file "sample.ex", [bar: "baz"]
199-
#=> "foo baz"
198+
EEx.eval_file "sample.ex", [bar: "baz"] #=> "foo baz"
200199
201200
"""
202201
def eval_file(filename, bindings \\ [], options \\ []) do

lib/eex/lib/eex/smart_engine.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ defmodule EEx.AssignsEngine do
6363
use EEx.AssignsEngine
6464
end
6565
66-
EEx.eval_string("<%= @foo %>", assigns: [foo: 1])
67-
#=> 1
66+
iex> EEx.eval_string("<%= @foo %>", assigns: [foo: 1])
67+
"1"
6868
6969
In the example above, we can access the value `foo` under
7070
the binding `assigns` using `@foo`. This is useful when

lib/eex/test/eex_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ end
4545
defmodule EExTest do
4646
use ExUnit.Case, async: true
4747

48+
doctest EEx
49+
doctest EEx.AssignsEngine
50+
4851
test "evaluates simple string" do
4952
assert_eval "foo bar", "foo bar"
5053
end

lib/elixir/lib/access.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ defprotocol Access do
1111
and dictionary like types:
1212
1313
iex> keywords = [a: 1, b: 2]
14-
...> keywords[:a]
14+
iex> keywords[:a]
1515
1
1616
1717
iex> map = %{ a: 1, b: 2 }
18-
...> map[:a]
18+
iex> map[:a]
1919
1
2020
2121
iex> star_ratings = %{ 1.0 => "★", 1.5 => "★☆", 2.0 => "★★" }
22-
...> star_ratings[1.5]
22+
iex> star_ratings[1.5]
2323
"★☆"
2424
2525
The key access must be implemented using the `===` operator.

lib/elixir/lib/bitwise.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule Bitwise do
1515
You can select to include only or skip operators by passing options:
1616
1717
iex> use Bitwise, only_operators: true
18-
...> 1 &&& 1
18+
iex> 1 &&& 1
1919
1
2020
2121
"""

lib/elixir/lib/code.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ defmodule Code do
136136
## Examples
137137
138138
iex> contents = quote(hygiene: [vars: false], do: a + b)
139-
...> Code.eval_quoted(contents, [a: 1, b: 2], file: __ENV__.file, line: __ENV__.line)
139+
iex> Code.eval_quoted(contents, [a: 1, b: 2], file: __ENV__.file, line: __ENV__.line)
140140
{3, [a: 1, b: 2]}
141141
142142
For convenience, you can pass `__ENV__` as the `opts` argument and
143143
all options will be automatically extracted from the current environment:
144144
145145
iex> contents = quote(hygiene: [vars: false], do: a + b)
146-
...> Code.eval_quoted(contents, [a: 1, b: 2], __ENV__)
146+
iex> Code.eval_quoted(contents, [a: 1, b: 2], __ENV__)
147147
{3, [a: 1, b: 2]}
148148
149149
"""

lib/elixir/lib/dict.ex

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ defmodule Dict do
2121
protocol:
2222
2323
iex> dict = dict_impl.new
24-
...> dict = Dict.put(dict, :hello, :world)
25-
...> dict[:hello]
24+
iex> dict = Dict.put(dict, :hello, :world)
25+
iex> dict[:hello]
2626
:world
2727
2828
As well as the `Enumerable` and `Collectable` protocols.
@@ -88,7 +88,7 @@ defmodule Dict do
8888
## Examples
8989
9090
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
91-
...> Enum.sort(Dict.keys(d))
91+
iex> Enum.sort(Dict.keys(d))
9292
[:a,:b]
9393
9494
"""
@@ -104,7 +104,7 @@ defmodule Dict do
104104
## Examples
105105
106106
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
107-
...> Enum.sort(Dict.values(d))
107+
iex> Enum.sort(Dict.values(d))
108108
[1,2]
109109
110110
"""
@@ -119,7 +119,7 @@ defmodule Dict do
119119
## Examples
120120
121121
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
122-
...> Dict.size(d)
122+
iex> Dict.size(d)
123123
2
124124
125125
"""
@@ -205,8 +205,8 @@ defmodule Dict do
205205
## Examples
206206
207207
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
208-
...> d = Dict.put(d, :a, 3)
209-
...> Dict.get(d, :a)
208+
iex> d = Dict.put(d, :a, 3)
209+
iex> Dict.get(d, :a)
210210
3
211211
212212
"""
@@ -221,8 +221,8 @@ defmodule Dict do
221221
## Examples
222222
223223
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
224-
...> d = Dict.put_new(d, :a, 3)
225-
...> Dict.get(d, :a)
224+
iex> d = Dict.put_new(d, :a, 3)
225+
iex> Dict.get(d, :a)
226226
1
227227
228228
"""
@@ -238,12 +238,12 @@ defmodule Dict do
238238
## Examples
239239
240240
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
241-
...> d = Dict.delete(d, :a)
242-
...> Dict.get(d, :a)
241+
iex> d = Dict.delete(d, :a)
242+
iex> Dict.get(d, :a)
243243
nil
244244
245245
iex> d = Enum.into([b: 2], dict_impl.new)
246-
...> Dict.delete(d, :a) == d
246+
iex> Dict.delete(d, :a) == d
247247
true
248248
249249
"""
@@ -266,17 +266,17 @@ defmodule Dict do
266266
## Examples
267267
268268
iex> d1 = Enum.into([a: 1, b: 2], dict_impl.new)
269-
...> d2 = Enum.into([a: 3, d: 4], dict_impl.new)
270-
...> d = Dict.merge(d1, d2)
271-
...> [a: Dict.get(d, :a), b: Dict.get(d, :b), d: Dict.get(d, :d)]
269+
iex> d2 = Enum.into([a: 3, d: 4], dict_impl.new)
270+
iex> d = Dict.merge(d1, d2)
271+
iex> [a: Dict.get(d, :a), b: Dict.get(d, :b), d: Dict.get(d, :d)]
272272
[a: 3, b: 2, d: 4]
273273
274274
iex> d1 = Enum.into([a: 1, b: 2], dict_impl.new)
275-
...> d2 = Enum.into([a: 3, d: 4], dict_impl.new)
276-
...> d = Dict.merge(d1, d2, fn(_k, v1, v2) ->
275+
iex> d2 = Enum.into([a: 3, d: 4], dict_impl.new)
276+
iex> d = Dict.merge(d1, d2, fn(_k, v1, v2) ->
277277
...> v1 + v2
278278
...> end)
279-
...> [a: Dict.get(d, :a), b: Dict.get(d, :b), d: Dict.get(d, :d)]
279+
iex> [a: Dict.get(d, :a), b: Dict.get(d, :b), d: Dict.get(d, :d)]
280280
[a: 4, b: 2, d: 4]
281281
282282
"""
@@ -301,18 +301,18 @@ defmodule Dict do
301301
## Examples
302302
303303
iex> dict = Enum.into([a: 1], dict_impl.new)
304-
...> {v, d} = Dict.pop dict, :a
305-
...> {v, Enum.sort(d)}
304+
iex> {v, d} = Dict.pop dict, :a
305+
iex> {v, Enum.sort(d)}
306306
{1,[]}
307307
308308
iex> dict = Enum.into([a: 1], dict_impl.new)
309-
...> {v, d} = Dict.pop dict, :b
310-
...> {v, Enum.sort(d)}
309+
iex> {v, d} = Dict.pop dict, :b
310+
iex> {v, Enum.sort(d)}
311311
{nil,[a: 1]}
312312
313313
iex> dict = Enum.into([a: 1], dict_impl.new)
314-
...> {v, d} = Dict.pop dict, :b, 3
315-
...> {v, Enum.sort(d)}
314+
iex> {v, d} = Dict.pop dict, :b, 3
315+
iex> {v, Enum.sort(d)}
316316
{3,[a: 1]}
317317
318318
"""
@@ -328,8 +328,8 @@ defmodule Dict do
328328
## Examples
329329
330330
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
331-
...> d = Dict.update!(d, :a, fn(val) -> -val end)
332-
...> Dict.get(d, :a)
331+
iex> d = Dict.update!(d, :a, fn(val) -> -val end)
332+
iex> Dict.get(d, :a)
333333
-1
334334
335335
"""
@@ -346,8 +346,8 @@ defmodule Dict do
346346
## Examples
347347
348348
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
349-
...> d = Dict.update(d, :c, 3, fn(val) -> -val end)
350-
...> Dict.get(d, :c)
349+
iex> d = Dict.update(d, :c, 3, fn(val) -> -val end)
350+
iex> Dict.get(d, :c)
351351
3
352352
353353
"""
@@ -366,18 +366,18 @@ defmodule Dict do
366366
## Examples
367367
368368
iex> d = Enum.into([a: 1, b: 2, c: 3, d: 4], dict_impl.new)
369-
...> { d1, d2 } = Dict.split(d, [:a, :c, :e])
370-
...> { Dict.to_list(d1) |> Enum.sort, Dict.to_list(d2) |> Enum.sort }
369+
iex> { d1, d2 } = Dict.split(d, [:a, :c, :e])
370+
iex> { Dict.to_list(d1) |> Enum.sort, Dict.to_list(d2) |> Enum.sort }
371371
{ [a: 1, c: 3], [b: 2, d: 4] }
372372
373373
iex> d = Enum.into([], dict_impl.new)
374-
...> { d1, d2 } = Dict.split(d, [:a, :c])
375-
...> { Dict.to_list(d1), Dict.to_list(d2) }
374+
iex> { d1, d2 } = Dict.split(d, [:a, :c])
375+
iex> { Dict.to_list(d1), Dict.to_list(d2) }
376376
{ [], [] }
377377
378378
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
379-
...> { d1, d2 } = Dict.split(d, [:a, :b, :c])
380-
...> { Dict.to_list(d1) |> Enum.sort, Dict.to_list(d2) }
379+
iex> { d1, d2 } = Dict.split(d, [:a, :b, :c])
380+
iex> { Dict.to_list(d1) |> Enum.sort, Dict.to_list(d2) }
381381
{ [a: 1, b: 2], [] }
382382
383383
"""
@@ -393,13 +393,13 @@ defmodule Dict do
393393
## Examples
394394
395395
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
396-
...> d = Dict.drop(d, [:a, :c, :d])
397-
...> Dict.to_list(d)
396+
iex> d = Dict.drop(d, [:a, :c, :d])
397+
iex> Dict.to_list(d)
398398
[b: 2]
399399
400400
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
401-
...> d = Dict.drop(d, [:c, :d])
402-
...> Dict.to_list(d) |> Enum.sort
401+
iex> d = Dict.drop(d, [:c, :d])
402+
iex> Dict.to_list(d) |> Enum.sort
403403
[a: 1, b: 2]
404404
405405
"""
@@ -416,13 +416,11 @@ defmodule Dict do
416416
## Examples
417417
418418
iex> d = Enum.into([a: 1, b: 2], dict_impl.new)
419-
...>
420-
...> d = Dict.take(d, [:a, :c, :d])
421-
...> Dict.to_list(d)
419+
iex> d = Dict.take(d, [:a, :c, :d])
420+
iex> Dict.to_list(d)
422421
[a: 1]
423-
...>
424-
...> d = Dict.take(d, [:c, :d])
425-
...> Dict.to_list(d)
422+
iex> d = Dict.take(d, [:c, :d])
423+
iex> Dict.to_list(d)
426424
[]
427425
428426
"""
@@ -447,13 +445,13 @@ defmodule Dict do
447445
## Examples
448446
449447
iex> a = Enum.into([a: 2, b: 3, f: 5, c: 123], dict_impl.new)
450-
...> b = [a: 2, b: 3, f: 5, c: 123]
451-
...> Dict.equal?(a, b)
448+
iex> b = [a: 2, b: 3, f: 5, c: 123]
449+
iex> Dict.equal?(a, b)
452450
true
453451
454452
iex> a = Enum.into([a: 2, b: 3, f: 5, c: 123], dict_impl.new)
455-
...> b = []
456-
...> Dict.equal?(a, b)
453+
iex> b = []
454+
iex> Dict.equal?(a, b)
457455
false
458456
459457
"""

0 commit comments

Comments
 (0)