Class: SyntaxTree::BraceBlock

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

BraceBlock represents passing a block to a method call using the { } operators.

method { |variable| variable + 1 }

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(lbrace:, block_var:, statements:, location:, comments: []) ⇒ BraceBlock



2144
2145
2146
2147
2148
2149
2150
# File 'lib/syntax_tree/node.rb', line 2144

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_varObject (readonly)

nil | BlockVar

the optional set of parameters to the block



2136
2137
2138
# File 'lib/syntax_tree/node.rb', line 2136

def block_var
  @block_var
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2142
2143
2144
# File 'lib/syntax_tree/node.rb', line 2142

def comments
  @comments
end

#lbraceObject (readonly)

LBrace

the left brace that opens this block



2133
2134
2135
# File 'lib/syntax_tree/node.rb', line 2133

def lbrace
  @lbrace
end

#statementsObject (readonly)

Statements

the list of expressions to evaluate within the block



2139
2140
2141
# File 'lib/syntax_tree/node.rb', line 2139

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



2152
2153
2154
# File 'lib/syntax_tree/node.rb', line 2152

def accept(visitor)
  visitor.visit_brace_block(self)
end

#child_nodesObject Also known as: deconstruct



2156
2157
2158
# File 'lib/syntax_tree/node.rb', line 2156

def child_nodes
  [lbrace, block_var, statements]
end

#deconstruct_keys(_keys) ⇒ Object



2162
2163
2164
2165
2166
2167
2168
2169
2170
# File 'lib/syntax_tree/node.rb', line 2162

def deconstruct_keys(_keys)
  {
    lbrace: lbrace,
    block_var: block_var,
    statements: statements,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



2172
2173
2174
# File 'lib/syntax_tree/node.rb', line 2172

def format(q)
  BlockFormatter.new(self, lbrace, "}", statements).format(q)
end