June 2023
Intermediate to advanced
274 pages
5h 17m
English
In this chapter, we will learn about one of the most powerful features of Elixir, metaprogramming. Writing a simple piece of Elixir code is referred to as programming, and writing Elixir code that programmatically injects behavior into other Elixir code is referred to as metaprogramming. Metaprogramming allows us to extend Elixir’s features and facilitate developer productivity by automating the otherwise tedious and manual process of adding repetitive boilerplate code.
Let’s take the Phoenix router, for example:
blog/lib/blog_web/router.ex
defmodule BlogWeb.Router do # .. pipeline :browser do plug :fetch_session plug :accepts, ["html"] end scope "/", BlogWeb do pipe_through [:browser] ...
Read now
Unlock full access