Skip to content

Instantly share code, notes, and snippets.

@microlith57
Last active April 23, 2019 04:58
Show Gist options
  • Save microlith57/b7ee26837550b1d9a80437d107c16419 to your computer and use it in GitHub Desktop.
Save microlith57/b7ee26837550b1d9a80437d107c16419 to your computer and use it in GitHub Desktop.
Hack on the Enum struct to allow for `Color.parse("Red | Green")`
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
@microlith57
Copy link
Author

Also, for YAML compatibility, you can:

struct Enum
  def new(i : Int64)
    new i.to_i32
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment