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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of BraceBlock.



1997
1998
1999
2000
2001
2002
2003
# File 'lib/syntax_tree/node.rb', line 1997

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



1989
1990
1991
# File 'lib/syntax_tree/node.rb', line 1989

def block_var
  @block_var
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1995
1996
1997
# File 'lib/syntax_tree/node.rb', line 1995

def comments
  @comments
end

#lbraceObject (readonly)

LBrace

the left brace that opens this block



1986
1987
1988
# File 'lib/syntax_tree/node.rb', line 1986

def lbrace
  @lbrace
end

#statementsObject (readonly)

Statements

the list of expressions to evaluate within the block



1992
1993
1994
# File 'lib/syntax_tree/node.rb', line 1992

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object



2005
2006
2007
# File 'lib/syntax_tree/node.rb', line 2005

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

#child_nodesObject Also known as: deconstruct



2009
2010
2011
# File 'lib/syntax_tree/node.rb', line 2009

def child_nodes
  [lbrace, block_var, statements]
end

#deconstruct_keys(keys) ⇒ Object



2015
2016
2017
2018
2019
2020
2021
2022
2023
# File 'lib/syntax_tree/node.rb', line 2015

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

#format(q) ⇒ Object



2025
2026
2027
# File 'lib/syntax_tree/node.rb', line 2025

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