Class: SyntaxTree::ConstPathField

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

ConstPathField represents the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced as a child of another variable.

object::Const = value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent:, constant:, location:, comments: []) ⇒ ConstPathField

Returns a new instance of ConstPathField.



4094
4095
4096
4097
4098
4099
# File 'lib/syntax_tree.rb', line 4094

def initialize(parent:, constant:, location:, comments: [])
  @parent = parent
  @constant = constant
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4092
4093
4094
# File 'lib/syntax_tree.rb', line 4092

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



4086
4087
4088
# File 'lib/syntax_tree.rb', line 4086

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



4089
4090
4091
# File 'lib/syntax_tree.rb', line 4089

def location
  @location
end

#parentObject (readonly)

untyped

the source of the constant



4083
4084
4085
# File 'lib/syntax_tree.rb', line 4083

def parent
  @parent
end

Instance Method Details

#child_nodesObject



4101
4102
4103
# File 'lib/syntax_tree.rb', line 4101

def child_nodes
  [parent, constant]
end

#format(q) ⇒ Object



4105
4106
4107
4108
4109
# File 'lib/syntax_tree.rb', line 4105

def format(q)
  q.format(parent)
  q.text("::")
  q.format(constant)
end

#pretty_print(q) ⇒ Object



4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
# File 'lib/syntax_tree.rb', line 4111

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("const_path_field")

    q.breakable
    q.pp(parent)

    q.breakable
    q.pp(constant)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



4125
4126
4127
4128
4129
4130
4131
4132
4133
# File 'lib/syntax_tree.rb', line 4125

def to_json(*opts)
  {
    type: :const_path_field,
    parent: parent,
    constant: constant,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end