Class: Drymm::Shapes::Const

Inherits:
Node
  • Object
show all
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.

Examples:

Wraps

Drymm::Shapes::Const[Dry]
# => #<Drymm::Shapes::Const name='Dry'>

Drymm::Shapes::Const[name: 'Dry'].to_literal
# => Dry

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

type_enum, type_identifier

Methods included from ASTMethods

#compile

Methods included from JSONMethods

#to_json

Class Method Details

.call(class_or_module_literal) ⇒ self .call(hash) ⇒ self

Overloads:

  • .call(class_or_module_literal) ⇒ self

    Parameters:

    • class_or_module_literal (Class, Module)
  • .call(hash) ⇒ self

    Parameters:

    • hash (Hash { :type => :const, :name => String })

Returns:

  • (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

.primitiveClass(Module)

Returns:

  • (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.

Parameters:

  • input (Any)

Returns:

  • (true)

    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_literalClass, Module Also known as: to_ast

Constantize by name

Returns:

  • (Class, Module)


22
23
24
# File 'lib/drymm/shapes/const.rb', line 22

def to_literal
  ::Object.const_get(name)
end