Class: SyntaxTree::ArgBlock
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::ArgBlock
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
ArgBlock represents using a block operator on an expression.
method(&expression)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- nil | Node
-
the expression being turned into a block.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ ArgBlock
Returns a new instance of ArgBlock.
894
895
896
897
898
|
# File 'lib/syntax_tree/node.rb', line 894
def initialize(value:, location:)
@value = value
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
892
893
894
|
# File 'lib/syntax_tree/node.rb', line 892
def
@comments
end
|
#value ⇒ Object
- nil | Node
-
the expression being turned into a block
889
890
891
|
# File 'lib/syntax_tree/node.rb', line 889
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
930
931
932
|
# File 'lib/syntax_tree/node.rb', line 930
def ===(other)
other.is_a?(ArgBlock) && value === other.value
end
|
#accept(visitor) ⇒ Object
900
901
902
|
# File 'lib/syntax_tree/node.rb', line 900
def accept(visitor)
visitor.visit_arg_block(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
904
905
906
|
# File 'lib/syntax_tree/node.rb', line 904
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
908
909
910
911
912
913
914
915
916
917
|
# File 'lib/syntax_tree/node.rb', line 908
def copy(value: nil, location: nil)
node =
ArgBlock.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
921
922
923
|
# File 'lib/syntax_tree/node.rb', line 921
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
925
926
927
928
|
# File 'lib/syntax_tree/node.rb', line 925
def format(q)
q.text("&")
q.format(value) if value
end
|