Class: SyntaxTree::BraceBlock
- Inherits:
-
Object
- Object
- SyntaxTree::BraceBlock
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the list of expressions to evaluate within the block.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lbrace:, block_var:, statements:, location:, comments: []) ⇒ BraceBlock
constructor
A new instance of BraceBlock.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(lbrace:, block_var:, statements:, location:, comments: []) ⇒ BraceBlock
Returns a new instance of BraceBlock.
2951 2952 2953 2954 2955 2956 2957 |
# File 'lib/syntax_tree.rb', line 2951 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
2940 2941 2942 |
# File 'lib/syntax_tree.rb', line 2940 def block_var @block_var end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2949 2950 2951 |
# File 'lib/syntax_tree.rb', line 2949 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that opens this block
2937 2938 2939 |
# File 'lib/syntax_tree.rb', line 2937 def lbrace @lbrace end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2946 2947 2948 |
# File 'lib/syntax_tree.rb', line 2946 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the list of expressions to evaluate within the block
2943 2944 2945 |
# File 'lib/syntax_tree.rb', line 2943 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
2959 2960 2961 |
# File 'lib/syntax_tree.rb', line 2959 def child_nodes [lbrace, block_var, statements] end |
#format(q) ⇒ Object
2963 2964 2965 |
# File 'lib/syntax_tree.rb', line 2963 def format(q) BlockFormatter.new(self, lbrace, "}", statements).format(q) end |
#pretty_print(q) ⇒ Object
2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 |
# File 'lib/syntax_tree.rb', line 2967 def pretty_print(q) q.group(2, "(", ")") do q.text("brace_block") if block_var q.breakable q.pp(block_var) end q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 |
# File 'lib/syntax_tree.rb', line 2983 def to_json(*opts) { type: :brace_block, lbrace: lbrace, block_var: block_var, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |