Class: Enu

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/enu.rb,
lib/enu/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject



20
21
22
# File 'lib/enu.rb', line 20

def options
  @options ||= {}.freeze
end

Class Method Details

.defaultObject



47
48
49
50
# File 'lib/enu.rb', line 47

def default
  raise "empty enum, sad enum" unless options&.any?
  keys.first
end

.inherited(descendant) ⇒ Object



42
43
44
45
# File 'lib/enu.rb', line 42

def inherited(descendant)
  inherited_frozen_options = options&.clone || {}.freeze
  descendant.class_eval { self.options = inherited_frozen_options }
end

.to_jsonObject



52
53
54
# File 'lib/enu.rb', line 52

def to_json
  keys.map { |key| [key, key] }.to_h.to_json
end