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.



1070
1071
1072
1073
1074
# File 'lib/syntax_tree.rb', line 1070

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



1068
1069
1070
# File 'lib/syntax_tree.rb', line 1068

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1065
1066
1067
# File 'lib/syntax_tree.rb', line 1065

def location
  @location
end

#partsObject (readonly)

Array[ untyped ]

the arguments that this node wraps



1062
1063
1064
# File 'lib/syntax_tree.rb', line 1062

def parts
  @parts
end

Instance Method Details

#child_nodesObject



1076
1077
1078
# File 'lib/syntax_tree.rb', line 1076

def child_nodes
  parts
end

#format(q) ⇒ Object



1080
1081
1082
# File 'lib/syntax_tree.rb', line 1080

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

#pretty_print(q) ⇒ Object



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/syntax_tree.rb', line 1084

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



1095
1096
1097
1098
1099
# File 'lib/syntax_tree.rb', line 1095

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