From 532984d012ad8a032db7e112ff00eef12cded1d8 Mon Sep 17 00:00:00 2001 From: Guilherme 'nirev' Nogueira Date: Wed, 16 Nov 2016 15:21:56 -0200 Subject: [PATCH] Add doc example for Module.eval_quoted with __ENV__ as first argument (#5455) --- lib/elixir/lib/module.ex | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/elixir/lib/module.ex b/lib/elixir/lib/module.ex index 303355577c..d26145ab7f 100644 --- a/lib/elixir/lib/module.ex +++ b/lib/elixir/lib/module.ex @@ -396,18 +396,24 @@ defmodule Module do Foo.sum(1, 2) #=> 3 - For convenience, you can pass `__ENV__/0` as an argument and - all options will be automatically extracted from the environment: + For convenience, you can pass any `Macro.Env` struct, such + as `__ENV__/0`, as the first argument or as options. Both + the module and all options will be automatically extracted + from the environment: defmodule Foo do contents = quote do: (def sum(a, b), do: a + b) - Module.eval_quoted __MODULE__, contents, [], __ENV__ + Module.eval_quoted __ENV__, contents end Foo.sum(1, 2) #=> 3 + Note that if you pass a `Macro.Env` struct as first argument + while also passing `opts`, they will be merged with `opts` + having precedence. + """ - def eval_quoted(module, quoted, binding \\ [], opts \\ []) + def eval_quoted(module_or_env, quoted, binding \\ [], opts \\ []) def eval_quoted(%Macro.Env{} = env, quoted, binding, opts) do eval_quoted(env.module, quoted, binding, Keyword.merge(Map.to_list(env), opts))