Skip to content

Instantly share code, notes, and snippets.

@pzac
Created November 10, 2023 15:36
Show Gist options
  • Save pzac/1ca2ca1649f2bb7dabf1550a8af4ed2d to your computer and use it in GitHub Desktop.
Save pzac/1ca2ca1649f2bb7dabf1550a8af4ed2d to your computer and use it in GitHub Desktop.
Data wrapper
class Success < Data.define(:result); end
class Failure < Data.define(:error); end
def foobar
if rand > 0.5
Success["Yes!!"]
else
Failure["Boooo"]
end
end
case foobar
in Success[result]
puts result
in Failure[error]
raise error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment