class SyntaxTree::Lambda
Lambda
represents using a lambda literal (not the lambda method call).
->(value) { value * 2 }
Attributes
BodyStmt
|Statements
-
the expressions to be executed in this lambda
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 7170 def initialize(params:, statements:, location:) @params = params @statements = statements @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 7254 def ===(other) other.is_a?(Lambda) && params === other.params && statements === other.statements end
Source
# File lib/syntax_tree/node.rb, line 7177 def accept(visitor) visitor.visit_lambda(self) end
Source
# File lib/syntax_tree/node.rb, line 7181 def child_nodes [params, statements] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 7185 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
Source
# File lib/syntax_tree/node.rb, line 7199 def deconstruct_keys(_keys) { params: params, statements: statements, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 7208 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 q.text("do") unless statements.empty? q.indent do q.breakable_space q.format(statements) end end q.breakable_space q.text("end") end .if_flat do q.text("{") unless statements.empty? q.text(" ") q.format(statements) q.text(" ") end q.text("}") end end end