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.



9236
9237
9238
9239
9240
# File 'lib/syntax_tree.rb', line 9236

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



9234
9235
9236
# File 'lib/syntax_tree.rb', line 9234

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9231
9232
9233
# File 'lib/syntax_tree.rb', line 9231

def location
  @location
end

#valueObject (readonly)

String

the period



9228
9229
9230
# File 'lib/syntax_tree.rb', line 9228

def value
  @value
end

Instance Method Details

#child_nodesObject



9242
9243
9244
# File 'lib/syntax_tree.rb', line 9242

def child_nodes
  []
end

#format(q) ⇒ Object



9246
9247
9248
# File 'lib/syntax_tree.rb', line 9246

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

#pretty_print(q) ⇒ Object



9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
# File 'lib/syntax_tree.rb', line 9250

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



9261
9262
9263
9264
9265
# File 'lib/syntax_tree.rb', line 9261

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