Class: SyntaxTree::BraceBlock
Overview
BraceBlock represents passing a block to a method call using the { } operators.
method { |variable| variable + 1 }
Instance Attribute Summary collapse
-
#block_var ⇒ Object
readonly
- nil | BlockVar
-
the optional set of parameters to the block.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#lbrace ⇒ Object
readonly
- LBrace
-
the left brace that opens this block.
-
#statements ⇒ Object
readonly
- Statements
-
the list of expressions to evaluate within the block.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lbrace:, block_var:, statements:, location:, comments: []) ⇒ BraceBlock
constructor
A new instance of BraceBlock.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lbrace:, block_var:, statements:, location:, comments: []) ⇒ BraceBlock
Returns a new instance of BraceBlock.
2086 2087 2088 2089 2090 2091 2092 |
# File 'lib/syntax_tree/node.rb', line 2086 def initialize(lbrace:, block_var:, statements:, location:, comments: []) @lbrace = lbrace @block_var = block_var @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#block_var ⇒ Object (readonly)
- nil | BlockVar
-
the optional set of parameters to the block
2078 2079 2080 |
# File 'lib/syntax_tree/node.rb', line 2078 def block_var @block_var end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2084 2085 2086 |
# File 'lib/syntax_tree/node.rb', line 2084 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that opens this block
2075 2076 2077 |
# File 'lib/syntax_tree/node.rb', line 2075 def lbrace @lbrace end |
#statements ⇒ Object (readonly)
- Statements
-
the list of expressions to evaluate within the block
2081 2082 2083 |
# File 'lib/syntax_tree/node.rb', line 2081 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
2094 2095 2096 |
# File 'lib/syntax_tree/node.rb', line 2094 def accept(visitor) visitor.visit_brace_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
2098 2099 2100 |
# File 'lib/syntax_tree/node.rb', line 2098 def child_nodes [lbrace, block_var, statements] end |
#deconstruct_keys(_keys) ⇒ Object
2104 2105 2106 2107 2108 2109 2110 2111 2112 |
# File 'lib/syntax_tree/node.rb', line 2104 def deconstruct_keys(_keys) { lbrace: lbrace, block_var: block_var, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
2114 2115 2116 |
# File 'lib/syntax_tree/node.rb', line 2114 def format(q) BlockFormatter.new(self, lbrace, "}", statements).format(q) end |