Class: ASE::Enum
- Inherits:
-
Object
- Object
- ASE::Enum
- Defined in:
- lib/as-extensions/enum.rb
Class Method Summary collapse
- .const_missing(key) ⇒ Object
-
.each_pair(&blk) ⇒ Object
Iterate over the key/value pairs in the Enum.
-
.include?(x) ⇒ Boolean
Check if a value is part of the Enum.
- .init(h) ⇒ Object
Class Method Details
.const_missing(key) ⇒ Object
25 26 27 28 |
# File 'lib/as-extensions/enum.rb', line 25 def const_missing(key) raise NameError "#{key} not in enum" unless @hash.has_key?(key) @hash[key] end |
.each_pair(&blk) ⇒ Object
Iterate over the key/value pairs in the Enum
31 32 33 |
# File 'lib/as-extensions/enum.rb', line 31 def each_pair(&blk) @hash.each_pair(&blk) end |
.include?(x) ⇒ Boolean
Check if a value is part of the Enum
44 45 46 |
# File 'lib/as-extensions/enum.rb', line 44 def include?(x) @hash.has_value?(x) end |
.init(h) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/as-extensions/enum.rb', line 35 def init(h) @hash = {} h.each_pair do |k,v| @hash[k] = v end self end |