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/Not.html below:

class SyntaxTree::Not - RDoc Documentation

  1. SyntaxTree::
  2. Not
class SyntaxTree::Not

Not represents the unary not method being called on an expression.

not value
Attributes
boolean

whether or not parentheses were used

boolean

whether or not parentheses were used

nil | Node

the statement on which to operate

Public Class Methods

Source

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

Source

def ===(other)
  other.is_a?(Not) && statement === other.statement &&
    parentheses === other.parentheses
end

Source

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

Source

def child_nodes
  [statement]
end

Source

def copy(statement: nil, parentheses: nil, location: nil)
  node =
    Not.new(
      statement: statement || self.statement,
      parentheses: parentheses || self.parentheses,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

Source

def deconstruct_keys(_keys)
  {
    statement: statement,
    parentheses: parentheses,
    location: location,
    comments: comments
  }
end

Source

def format(q)
  q.text("not")

  if parentheses
    q.text("(")
    q.format(statement) if statement
    q.text(")")
  else
    grandparent = q.grandparent
    ternary =
      (grandparent.is_a?(IfNode) || grandparent.is_a?(UnlessNode)) &&
        Ternaryable.call(q, grandparent)

    if ternary
      q.if_break { q.text(" ") }.if_flat { q.text("(") }
      q.format(statement) if statement
      q.if_flat { q.text(")") } if ternary
    else
      q.text(" ")
      q.format(statement) if statement
    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