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.



9312
9313
9314
9315
9316
# File 'lib/syntax_tree.rb', line 9312

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



9310
9311
9312
# File 'lib/syntax_tree.rb', line 9310

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9307
9308
9309
# File 'lib/syntax_tree.rb', line 9307

def location
  @location
end

#valueObject (readonly)

String

the period



9304
9305
9306
# File 'lib/syntax_tree.rb', line 9304

def value
  @value
end

Instance Method Details

#child_nodesObject



9318
9319
9320
# File 'lib/syntax_tree.rb', line 9318

def child_nodes
  []
end

#format(q) ⇒ Object



9322
9323
9324
# File 'lib/syntax_tree.rb', line 9322

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

#pretty_print(q) ⇒ Object



9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
# File 'lib/syntax_tree.rb', line 9326

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



9337
9338
9339
9340
9341
# File 'lib/syntax_tree.rb', line 9337

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