A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://ruby-syntax-tree.github.io/syntax_tree/SyntaxTree/Lambda.html below:

class SyntaxTree::Lambda - RDoc Documentation

  1. SyntaxTree::
  2. Lambda
class SyntaxTree::Lambda

Lambda represents using a lambda literal (not the lambda method call).

->(value) { value * 2 }
Attributes Public Class Methods

Source

def initialize(params:, statements:, location:)
  @params = params
  @statements = statements
  @location = location
  @comments = []
end
Public Instance Methods

Source

def ===(other)
  other.is_a?(Lambda) && params === other.params &&
    statements === other.statements
end

Source

def accept(visitor)
  visitor.visit_lambda(self)
end

Source

def child_nodes
  [params, statements]
end

Source

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

def deconstruct_keys(_keys)
  {
    params: params,
    statements: statements,
    location: location,
    comments: comments
  }
end

Source

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

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