Class: SyntaxTree::ArgBlock
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 | untyped
-
the expression being turned into a block.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ ArgBlock
constructor
A new instance of ArgBlock.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ ArgBlock
Returns a new instance of ArgBlock.
755 756 757 758 759 |
# File 'lib/syntax_tree/node.rb', line 755 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
753 754 755 |
# File 'lib/syntax_tree/node.rb', line 753 def comments @comments end |
#value ⇒ Object (readonly)
- nil | untyped
-
the expression being turned into a block
750 751 752 |
# File 'lib/syntax_tree/node.rb', line 750 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
761 762 763 |
# File 'lib/syntax_tree/node.rb', line 761 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
767 768 769 |
# File 'lib/syntax_tree/node.rb', line 767 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
771 772 773 774 |
# File 'lib/syntax_tree/node.rb', line 771 def format(q) q.text("&") q.format(value) if value end |
#pretty_print(q) ⇒ Object
776 777 778 779 780 781 782 783 784 785 786 787 |
# File 'lib/syntax_tree/node.rb', line 776 def pretty_print(q) q.group(2, "(", ")") do q.text("arg_block") if value q.breakable q.pp(value) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
789 790 791 792 793 |
# File 'lib/syntax_tree/node.rb', line 789 def to_json(*opts) { type: :arg_block, value: value, loc: location, cmts: comments }.to_json( *opts ) end |