Class: SyntaxTree::Args

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

Overview

Args represents a list of arguments being passed to a method call or array literal.

method(first, second, third)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts:, location:, comments: []) ⇒ Args

Returns a new instance of Args.



1121
1122
1123
1124
1125
# File 'lib/syntax_tree.rb', line 1121

def initialize(parts:, location:, comments: [])
  @parts = parts
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1119
1120
1121
# File 'lib/syntax_tree.rb', line 1119

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1116
1117
1118
# File 'lib/syntax_tree.rb', line 1116

def location
  @location
end

#partsObject (readonly)

Array[ untyped ]

the arguments that this node wraps



1113
1114
1115
# File 'lib/syntax_tree.rb', line 1113

def parts
  @parts
end

Instance Method Details

#child_nodesObject



1127
1128
1129
# File 'lib/syntax_tree.rb', line 1127

def child_nodes
  parts
end

#format(q) ⇒ Object



1131
1132
1133
# File 'lib/syntax_tree.rb', line 1131

def format(q)
  q.seplist(parts) { |part| q.format(part) }
end

#pretty_print(q) ⇒ Object



1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'lib/syntax_tree.rb', line 1135

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

    q.breakable
    q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } }

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

#to_json(*opts) ⇒ Object



1146
1147
1148
1149
1150
# File 'lib/syntax_tree.rb', line 1146

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