Skip to content

Instantly share code, notes, and snippets.

@sinsoku
Created June 24, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinsoku/0c11f108502d96239d01acaba7c3ddb6 to your computer and use it in GitHub Desktop.
Save sinsoku/0c11f108502d96239d01acaba7c3ddb6 to your computer and use it in GitHub Desktop.
enum = Enum.new(:a, :b, :c)
status = :b
# pattern 1
enum.case status do
_when(:a) do
p :a
end
_when :b do
p :b
end
_when :c do
p :c
end
end
# pattern 2
enum.case(status)
.when(:a) do
p :a
end.when(:b) do
p :b
end.when(:c) do
p :c
end.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment