Class: SyntaxTree::Args
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Args
show all
- Defined in:
- lib/syntax_tree/node.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
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#parts ⇒ Object
readonly
- Array[ untyped ]
-
the arguments that this node wraps.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parts:, location:) ⇒ Args
Returns a new instance of Args.
817
818
819
820
821
|
# File 'lib/syntax_tree/node.rb', line 817
def initialize(parts:, location:)
@parts = parts
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
815
816
817
|
# File 'lib/syntax_tree/node.rb', line 815
def
end
|
#parts ⇒ Object
- Array[ untyped ]
-
the arguments that this node wraps
812
813
814
|
# File 'lib/syntax_tree/node.rb', line 812
def parts
@parts
end
|
Instance Method Details
#===(other) ⇒ Object
852
853
854
|
# File 'lib/syntax_tree/node.rb', line 852
def ===(other)
other.is_a?(Args) && ArrayMatch.call(parts, other.parts)
end
|
#accept(visitor) ⇒ Object
823
824
825
|
# File 'lib/syntax_tree/node.rb', line 823
def accept(visitor)
visitor.visit_args(self)
end
|
#arity ⇒ Object
856
857
858
859
860
861
862
863
864
865
866
867
868
869
|
# File 'lib/syntax_tree/node.rb', line 856
def arity
parts.sum do |part|
case part
when ArgStar, ArgsForward
Float::INFINITY
when BareAssocHash
part.assocs.sum do |assoc|
assoc.is_a?(AssocSplat) ? Float::INFINITY : 1
end
else
1
end
end
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
827
828
829
|
# File 'lib/syntax_tree/node.rb', line 827
def child_nodes
parts
end
|
#copy(parts: nil, location: nil) ⇒ Object
831
832
833
834
835
836
837
838
839
840
|
# File 'lib/syntax_tree/node.rb', line 831
def copy(parts: nil, location: nil)
node =
Args.new(
parts: parts || self.parts,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
844
845
846
|
# File 'lib/syntax_tree/node.rb', line 844
def deconstruct_keys(_keys)
{ parts: parts, location: location, comments: }
end
|
848
849
850
|
# File 'lib/syntax_tree/node.rb', line 848
def format(q)
q.seplist(parts) { |part| q.format(part) }
end
|