Last active
August 29, 2015 14:14
-
-
Save rectalogic/b5fedcd0b1b14b50d9ab to your computer and use it in GitHub Desktop.
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
class Enum(object): | |
def __init__(self, **kwargs): | |
self._values = set() | |
for k, v in kwargs.items(): | |
setattr(self, k, v) | |
self._values.add(v) | |
def validate(self, values): | |
return set(values).issubset(self._values) | |
>>> Colors = Enum(RED="red", GREEN="green", BLUE="blue") | |
>>> Colors.GREEN | |
'green' | |
>>> Colors.validate(["red", "yellow"]) | |
False | |
>>> Colors.validate(["red", "green"]) | |
True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment