Last active
December 21, 2015 18:39
-
-
Save chrismccord/6349128 to your computer and use it in GitHub Desktop.
Access protocol only for specific record
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
defrecord User, email: nil | |
defmodule Access.User do | |
def access(record, attr), do: apply(elem(record, 0), attr, [record]) | |
end | |
user = User.new(email: "[email protected]") | |
iex> user[:email] | |
"[email protected]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment