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.



8835
8836
8837
8838
8839
# File 'lib/syntax_tree.rb', line 8835

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



8833
8834
8835
# File 'lib/syntax_tree.rb', line 8833

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8830
8831
8832
# File 'lib/syntax_tree.rb', line 8830

def location
  @location
end

#valueObject (readonly)

String

the period



8827
8828
8829
# File 'lib/syntax_tree.rb', line 8827

def value
  @value
end

Instance Method Details

#child_nodesObject



8841
8842
8843
# File 'lib/syntax_tree.rb', line 8841

def child_nodes
  []
end

#format(q) ⇒ Object



8845
8846
8847
# File 'lib/syntax_tree.rb', line 8845

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

#pretty_print(q) ⇒ Object



8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
# File 'lib/syntax_tree.rb', line 8849

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



8860
8861
8862
8863
8864
# File 'lib/syntax_tree.rb', line 8860

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