Skip to content

Instantly share code, notes, and snippets.

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