Block represents passing a block to a method call using the do
and end
keywords or the +{+ and +}+ operators.
method do |value| end method { |value| }Attributes
BlockVar
the optional variable declaration within this block
LBrace
| Kw
the left brace or the do keyword that opens this block
def initialize(opening:, block_var:, bodystmt:, location:) @opening = opening @block_var = block_var @bodystmt = bodystmt @location = location @comments = [] endPublic Instance Methods Source
def ===(other) other.is_a?(BlockNode) && opening === other.opening && block_var === other.block_var && bodystmt === other.bodystmt endSource
def accept(visitor) visitor.visit_block(self) endSource
def arity case block_var when BlockVar block_var.params.arity else 0..0 end endSource
def child_nodes [opening, block_var, bodystmt] endSource
def copy(opening: nil, block_var: nil, bodystmt: nil, location: nil) node = BlockNode.new( opening: opening || self.opening, block_var: block_var || self.block_var, bodystmt: bodystmt || self.bodystmt, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node endSource
def deconstruct_keys(_keys) { opening: opening, block_var: block_var, bodystmt: bodystmt, location: location, comments: comments } endSource
def format(q) break_opening, break_closing, flat_opening, flat_closing = if unchangeable_bounds?(q) block_close = keywords? ? "end" : "}" [opening.value, block_close, opening.value, block_close] elsif forced_do_end_bounds?(q) %w[do end do end] elsif forced_brace_bounds?(q) %w[{ } { }] else %w[do end { }] end case q.parent when nil, Command, CommandCall q.break_parent format_break(q, break_opening, break_closing) return end q.group do q .if_break { format_break(q, break_opening, break_closing) } .if_flat { format_flat(q, flat_opening, flat_closing) } end endSource
def keywords? opening.is_a?(Kw) end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4