Created
April 19, 2013 12:15
-
-
Save xpepper/5419968 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 | |
def self.new | |
Class.new do | |
def self.const_missing(name) | |
const_set(name, new) | |
end | |
end | |
end | |
end | |
Color = Enum.new | |
ThreatLevel = Enum.new | |
puts Color::Red # => #<Color:0x100189b28> | |
puts Color::Blue # => #<Color:0x100189a60> | |
puts Color::Red != Color::Blue # => true | |
puts Color::Red == Color::Red # => true | |
puts Color::Orange != ThreatLevel::Orange # => true | |
p Color.constants # => ["Blue", "Red", "Orange"] | |
p ThreatLevel.constants # => ["Orange"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment