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
Constructor Details
#initialize(call:, block:, location:, comments: []) ⇒ MethodAddBlock
6037 6038 6039 6040 6041 6042 |
# File 'lib/syntax_tree/node.rb', line 6037 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
6032 6033 6034 |
# File 'lib/syntax_tree/node.rb', line 6032 def block @block end |
#call ⇒ Object (readonly)
- Call | Command | CommandCall | FCall
-
the method call
6029 6030 6031 |
# File 'lib/syntax_tree/node.rb', line 6029 def call @call end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6035 6036 6037 |
# File 'lib/syntax_tree/node.rb', line 6035 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
6044 6045 6046 |
# File 'lib/syntax_tree/node.rb', line 6044 def accept(visitor) visitor.visit_method_add_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6048 6049 6050 |
# File 'lib/syntax_tree/node.rb', line 6048 def child_nodes [call, block] end |
#deconstruct_keys(keys) ⇒ Object
6054 6055 6056 |
# File 'lib/syntax_tree/node.rb', line 6054 def deconstruct_keys(keys) { call: call, block: block, location: location, comments: comments } end |
#format(q) ⇒ Object
6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 |
# File 'lib/syntax_tree/node.rb', line 6058 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 { q.if_break { CallChainFormatter.new(self).format(q) }.if_flat { format_contents(q) } } else format_contents(q) end end |
#format_contents(q) ⇒ Object
6069 6070 6071 6072 |
# File 'lib/syntax_tree/node.rb', line 6069 def format_contents(q) q.format(call) q.format(block) end |