Class: SyntaxTree::MethodAddBlock
Overview
MethodAddBlock represents a method call with a block argument.
method {}
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
- BraceBlock | DoBlock
-
the block being sent with the method call.
-
#call ⇒ Object
readonly
- Call | Command | CommandCall | FCall
-
the method call.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
- #format_contents(q) ⇒ Object
-
#initialize(call:, block:, location:, comments: []) ⇒ MethodAddBlock
constructor
A new instance of MethodAddBlock.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(call:, block:, location:, comments: []) ⇒ MethodAddBlock
Returns a new instance of MethodAddBlock.
6245 6246 6247 6248 6249 6250 |
# File 'lib/syntax_tree/node.rb', line 6245 def initialize(call:, block:, location:, comments: []) @call = call @block = block @location = location @comments = comments end |
Instance Attribute Details
#block ⇒ Object (readonly)
- BraceBlock | DoBlock
-
the block being sent with the method call
6240 6241 6242 |
# File 'lib/syntax_tree/node.rb', line 6240 def block @block end |
#call ⇒ Object (readonly)
- Call | Command | CommandCall | FCall
-
the method call
6237 6238 6239 |
# File 'lib/syntax_tree/node.rb', line 6237 def call @call end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6243 6244 6245 |
# File 'lib/syntax_tree/node.rb', line 6243 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
6252 6253 6254 |
# File 'lib/syntax_tree/node.rb', line 6252 def accept(visitor) visitor.visit_method_add_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6256 6257 6258 |
# File 'lib/syntax_tree/node.rb', line 6256 def child_nodes [call, block] end |
#deconstruct_keys(_keys) ⇒ Object
6262 6263 6264 |
# File 'lib/syntax_tree/node.rb', line 6262 def deconstruct_keys(_keys) { call: call, block: block, location: location, comments: comments } end |
#format(q) ⇒ Object
6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 |
# File 'lib/syntax_tree/node.rb', line 6266 def format(q) # If we're at the top of a call chain, then we're going to do some # specialized printing in case we can print it nicely. We _only_ do this # at the top of the chain to avoid weird recursion issues. if !CallChainFormatter.chained?(q.parent) && CallChainFormatter.chained?(call) q.group do q .if_break { CallChainFormatter.new(self).format(q) } .if_flat { format_contents(q) } end else format_contents(q) end end |
#format_contents(q) ⇒ Object
6282 6283 6284 6285 |
# File 'lib/syntax_tree/node.rb', line 6282 def format_contents(q) q.format(call) q.format(block) end |