class SyntaxTree::Lambda
->(value) { value * 2 }
Lambda represents using a lambda literal (not the lambda method call).
def ===(other)
def ===(other) other.is_a?(Lambda) && params === other.params && statements === other.statements end
def accept(visitor)
def accept(visitor) visitor.visit_lambda(self) end
def child_nodes
def child_nodes [params, statements] end
def copy(params: nil, statements: nil, location: nil)
def copy(params: nil, statements: nil, location: nil) node = Lambda.new( params: params || self.params, statements: statements || self.statements, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { params: params, statements: statements, location: location, comments: comments } end
def format(q)
def format(q) params = self.params q.text("->") q.group do if params.is_a?(Paren) q.format(params) unless params.contents.empty? elsif params.empty? && params.comments.any? q.format(params) elsif !params.empty? q.group do q.text("(") q.format(params) q.text(")") end end q.text(" ") q .if_break do force_parens = q.parents.any? do |node| node.is_a?(Command) || node.is_a?(CommandCall) end if force_parens q.text("{") unless statements.empty? q.indent do q.breakable_space q.format(statements) end q.breakable_space end q.text("}") else q.text("do") unless statements.empty? q.indent do q.breakable_space q.format(statements) end end q.breakable_space q.text("end") end end .if_flat do q.text("{") unless statements.empty? q.text(" ") q.format(statements) q.text(" ") end q.text("}") end end end
def initialize(params:, statements:, location:)
def initialize(params:, statements:, location:) @params = params @statements = statements @location = location @comments = [] end