Class: SyntaxTree::IVar

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

Overview

IVar represents an instance variable literal.

@variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ IVar

Returns a new instance of IVar.



7479
7480
7481
7482
7483
# File 'lib/syntax_tree.rb', line 7479

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7477
7478
7479
# File 'lib/syntax_tree.rb', line 7477

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7474
7475
7476
# File 'lib/syntax_tree.rb', line 7474

def location
  @location
end

#valueObject (readonly)

String

the name of the instance variable



7471
7472
7473
# File 'lib/syntax_tree.rb', line 7471

def value
  @value
end

Instance Method Details

#child_nodesObject



7485
7486
7487
# File 'lib/syntax_tree.rb', line 7485

def child_nodes
  []
end

#format(q) ⇒ Object



7489
7490
7491
# File 'lib/syntax_tree.rb', line 7489

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
# File 'lib/syntax_tree.rb', line 7493

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



7504
7505
7506
7507
7508
# File 'lib/syntax_tree.rb', line 7504

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