Last active
April 23, 2019 04:58
-
-
Save microlith57/b7ee26837550b1d9a80437d107c16419 to your computer and use it in GitHub Desktop.
Hack on the Enum struct to allow for `Color.parse("Red | Green")`
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
struct Enum | |
def self.parse?(string : String) : self? | |
parts = string.split("|") | |
output = new(0) | |
parts.each do |part| | |
p = previous_def(part.strip) | |
return nil if p.nil? | |
output |= p | |
end | |
output | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, for
YAML
compatibility, you can: