Skip to content

Instantly share code, notes, and snippets.

@bricker
Last active August 29, 2015 14:26
Show Gist options
  • Save bricker/82415e1e5a6fcd28f1a6 to your computer and use it in GitHub Desktop.
Save bricker/82415e1e5a6fcd28f1a6 to your computer and use it in GitHub Desktop.
def self.enum(keys)
OpenStruct.new(Hash[keys.map{|v| [v,v]}])
end
CoolEnum = enum %w{
ListItemA
ListItemB
ListItemC
}
# Preferably
CoolEnum.ListItemD #=> NoMethodError
# Reality
CoolEnum.ListItemD #=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment