Class: Drymm::Shapes::Const
- Defined in:
- lib/drymm/shapes/const.rb
Overview
The intermediary shape class to handle bidirectional serialization of classes & modules, referenced in the node’s AST.
Class Method Summary collapse
- .call(input, &block) ⇒ self
- .call_safe(input, &block) ⇒ Object private
- .call_unsafe(input) ⇒ Object private
- .primitive ⇒ Class(Module)
-
.primitive?(input) ⇒ true
If the input is an instance of Module class.
- .try(input, &block) ⇒ Object private
Instance Method Summary collapse
-
#to_literal ⇒ Class, Module
(also: #to_ast)
Constantize by name.
Methods inherited from Node
Methods included from ASTMethods
Methods included from JSONMethods
Class Method Details
.call(class_or_module_literal) ⇒ self .call(hash) ⇒ self
|
# File 'lib/drymm/shapes/const.rb', line 29
|
.call_safe(input, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 |
# File 'lib/drymm/shapes/const.rb', line 55 def call_safe(input, &block) return super unless primitive?(input) super(name: input, &block) end |
.call_unsafe(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 |
# File 'lib/drymm/shapes/const.rb', line 48 def call_unsafe(input) return super unless primitive?(input) super(name: input) end |
.primitive ⇒ Class(Module)
37 38 39 |
# File 'lib/drymm/shapes/const.rb', line 37 def primitive ::Module end |
.primitive?(input) ⇒ true
Returns if the input is an instance of Module class.
43 44 45 |
# File 'lib/drymm/shapes/const.rb', line 43 def primitive?(input) input.is_a?(primitive) end |
.try(input, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 65 66 |
# File 'lib/drymm/shapes/const.rb', line 62 def try(input, &block) return super unless primitive?(input) super(name: input, &block) end |
Instance Method Details
#to_literal ⇒ Class, Module Also known as: to_ast
Constantize by name
22 23 24 |
# File 'lib/drymm/shapes/const.rb', line 22 def to_literal ::Object.const_get(name) end |