class SyntaxTree::Lambda
Lambda
represents using a lambda literal (not the lambda method call).
->(value) { value * 2 }
Attributes
statements[R]
BodyStmt
|Statements
-
the expressions to be executed in this lambda
Public Class Methods
new(params:, statements:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 7155 def initialize(params:, statements:, location:) @params = params @statements = statements @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 7239 def ===(other) other.is_a?(Lambda) && params === other.params && statements === other.statements end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 7162 def accept(visitor) visitor.visit_lambda(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 7166 def child_nodes [params, statements] end
Also aliased as: deconstruct
copy(params: nil, statements: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 7170 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
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 7184 def deconstruct_keys(_keys) { params: params, statements: statements, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 7193 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