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
Constructor Details
#initialize(lbrace:, block_var:, statements:, location:, comments: []) ⇒ BraceBlock
Returns a new instance of BraceBlock.
2045 2046 2047 2048 2049 2050 2051 |
# File 'lib/syntax_tree/node.rb', line 2045 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
2037 2038 2039 |
# File 'lib/syntax_tree/node.rb', line 2037 def block_var @block_var end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2043 2044 2045 |
# File 'lib/syntax_tree/node.rb', line 2043 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that opens this block
2034 2035 2036 |
# File 'lib/syntax_tree/node.rb', line 2034 def lbrace @lbrace end |
#statements ⇒ Object (readonly)
- Statements
-
the list of expressions to evaluate within the block
2040 2041 2042 |
# File 'lib/syntax_tree/node.rb', line 2040 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
2053 2054 2055 |
# File 'lib/syntax_tree/node.rb', line 2053 def accept(visitor) visitor.visit_brace_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
2057 2058 2059 |
# File 'lib/syntax_tree/node.rb', line 2057 def child_nodes [lbrace, block_var, statements] end |
#deconstruct_keys(keys) ⇒ Object
2063 2064 2065 2066 2067 2068 2069 2070 2071 |
# File 'lib/syntax_tree/node.rb', line 2063 def deconstruct_keys(keys) { lbrace: lbrace, block_var: block_var, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
2073 2074 2075 |
# File 'lib/syntax_tree/node.rb', line 2073 def format(q) BlockFormatter.new(self, lbrace, "}", statements).format(q) end |