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.



4231
4232
4233
4234
4235
# File 'lib/syntax_tree.rb', line 4231

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



4229
4230
4231
# File 'lib/syntax_tree.rb', line 4229

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



4223
4224
4225
# File 'lib/syntax_tree.rb', line 4223

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



4226
4227
4228
# File 'lib/syntax_tree.rb', line 4226

def location
  @location
end

Instance Method Details

#child_nodesObject



4237
4238
4239
# File 'lib/syntax_tree.rb', line 4237

def child_nodes
  [constant]
end

#format(q) ⇒ Object



4241
4242
4243
# File 'lib/syntax_tree.rb', line 4241

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

#pretty_print(q) ⇒ Object



4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
# File 'lib/syntax_tree.rb', line 4245

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



4256
4257
4258
4259
4260
4261
4262
4263
# File 'lib/syntax_tree.rb', line 4256

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