Skip to content

Instantly share code, notes, and snippets.

@TylerPachal
Last active August 11, 2018 14:14
Show Gist options
  • Select an option

  • Save TylerPachal/bbbb900e8ebad0669590e7cfe6174aa2 to your computer and use it in GitHub Desktop.

Select an option

Save TylerPachal/bbbb900e8ebad0669590e7cfe6174aa2 to your computer and use it in GitHub Desktop.
# Using match?/2 with a guard statement
user = User.find(123)
can_access = match?(%{role: r, name: "tyler"} when r in ["owner", "admin"], user)
if can_access do
# 200
else
# 403
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment