Class: SyntaxTree::Period

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

Overview

Period represents the use of the . operator. It is usually found in method calls.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Period.



9444
9445
9446
9447
9448
# File 'lib/syntax_tree.rb', line 9444

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



9442
9443
9444
# File 'lib/syntax_tree.rb', line 9442

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9439
9440
9441
# File 'lib/syntax_tree.rb', line 9439

def location
  @location
end

#valueObject (readonly)

String

the period



9436
9437
9438
# File 'lib/syntax_tree.rb', line 9436

def value
  @value
end

Instance Method Details

#child_nodesObject



9450
9451
9452
# File 'lib/syntax_tree.rb', line 9450

def child_nodes
  []
end

#format(q) ⇒ Object



9454
9455
9456
# File 'lib/syntax_tree.rb', line 9454

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

#pretty_print(q) ⇒ Object



9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
# File 'lib/syntax_tree.rb', line 9458

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



9469
9470
9471
9472
9473
# File 'lib/syntax_tree.rb', line 9469

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