Class: SyntaxTree::Period

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

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Period.



7852
7853
7854
7855
7856
# File 'lib/syntax_tree/node.rb', line 7852

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



7850
7851
7852
# File 'lib/syntax_tree/node.rb', line 7850

def comments
  @comments
end

#valueObject (readonly)

String

the period



7847
7848
7849
# File 'lib/syntax_tree/node.rb', line 7847

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



7858
7859
7860
# File 'lib/syntax_tree/node.rb', line 7858

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



7864
7865
7866
# File 'lib/syntax_tree/node.rb', line 7864

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



7868
7869
7870
# File 'lib/syntax_tree/node.rb', line 7868

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

#pretty_print(q) ⇒ Object



7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
# File 'lib/syntax_tree/node.rb', line 7872

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



7883
7884
7885
7886
7887
# File 'lib/syntax_tree/node.rb', line 7883

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