Class: SoberSwag::Nodes::Enum
Overview
Compiler node to represent an enum value. Enums are special enough to have their own node, as they are basically a constant list of always-string values.
Instance Attribute Summary collapse
-
#values ⇒ Array<Symbol,String>
readonly
Values of the enum.
Instance Method Summary collapse
- #cata(&block) ⇒ Object
-
#deconstruct ⇒ Array(Array<Symbol,String>)
Deconstructs into the enum values.
-
#deconstruct_keys(_keys) ⇒ Hash{Symbol => Array<Symbol,String>}
The values, wrapped in a
values:
key. -
#initialize(values) ⇒ Enum
constructor
A new instance of Enum.
-
#map ⇒ Object
Since there is nothing to map over, this node will never actually call the block given.
Methods inherited from Base
Constructor Details
#initialize(values) ⇒ Enum
Returns a new instance of Enum.
7 8 9 |
# File 'lib/sober_swag/nodes/enum.rb', line 7 def initialize(values) @values = values end |
Instance Attribute Details
#values ⇒ Array<Symbol,String> (readonly)
Returns values of the enum.
13 14 15 |
# File 'lib/sober_swag/nodes/enum.rb', line 13 def values @values end |
Instance Method Details
#cata(&block) ⇒ Object
40 41 42 |
# File 'lib/sober_swag/nodes/enum.rb', line 40 def cata(&block) block.call(dup) end |
#deconstruct ⇒ Array(Array<Symbol,String>)
Deconstructs into the enum values.
27 28 29 |
# File 'lib/sober_swag/nodes/enum.rb', line 27 def deconstruct [values] end |
#deconstruct_keys(_keys) ⇒ Hash{Symbol => Array<Symbol,String>}
Returns the values, wrapped in a values:
key.
34 35 36 |
# File 'lib/sober_swag/nodes/enum.rb', line 34 def deconstruct_keys(_keys) { values: values } end |
#map ⇒ Object
Since there is nothing to map over, this node will never actually call the block given.
19 20 21 |
# File 'lib/sober_swag/nodes/enum.rb', line 19 def map dup end |