Class: NxtSupport::Enum
- Inherits:
-
Object
- Object
- NxtSupport::Enum
- Defined in:
- lib/nxt_support/util/enum.rb
Defined Under Namespace
Classes: Value
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(*keys) ⇒ Enum
constructor
A new instance of Enum.
- #to_h ⇒ Object
Constructor Details
#initialize(*keys) ⇒ Enum
Returns a new instance of Enum.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/nxt_support/util/enum.rb', line 3 def initialize(*keys) @store = ActiveSupport::HashWithIndifferentAccess.new keys.each do |key| normalized_key = normalized_key(key) store[normalized_key] = NxtSupport::Enum::Value.new(key) define_getter(normalized_key) end freeze end |
Class Method Details
.[](*keys) ⇒ Object
15 16 17 |
# File 'lib/nxt_support/util/enum.rb', line 15 def self.[](*keys) new(*keys) end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 |
# File 'lib/nxt_support/util/enum.rb', line 19 def [](key) store[key] || (raise KeyError, "No value for key '#{key}' in #{store}") end |
#to_h ⇒ Object
23 24 25 |
# File 'lib/nxt_support/util/enum.rb', line 23 def to_h store end |