Class: SyntaxTree::ConstRef

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

Overview

ConstRef represents the name of the constant being used in a class or module declaration.

class Container
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstRef.



4194
4195
4196
4197
4198
# File 'lib/syntax_tree.rb', line 4194

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4192
4193
4194
# File 'lib/syntax_tree.rb', line 4192

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



4186
4187
4188
# File 'lib/syntax_tree.rb', line 4186

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



4189
4190
4191
# File 'lib/syntax_tree.rb', line 4189

def location
  @location
end

Instance Method Details

#child_nodesObject



4200
4201
4202
# File 'lib/syntax_tree.rb', line 4200

def child_nodes
  [constant]
end

#format(q) ⇒ Object



4204
4205
4206
# File 'lib/syntax_tree.rb', line 4204

def format(q)
  q.format(constant)
end

#pretty_print(q) ⇒ Object



4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
# File 'lib/syntax_tree.rb', line 4208

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

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



4219
4220
4221
4222
4223
4224
4225
4226
# File 'lib/syntax_tree.rb', line 4219

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