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

class SyntaxTree::IfOp - RDoc Documentation

  1. SyntaxTree::
  2. IfOp
class SyntaxTree::IfOp

IfOp represents a ternary clause.

predicate ? truthy : falsy
Attributes
Node

the expression to be executed if the predicate is falsy

Node

the expression to be checked

Node

the expression to be executed if the predicate is truthy

Public Class Methods

Source

def initialize(predicate:, truthy:, falsy:, location:)
  @predicate = predicate
  @truthy = truthy
  @falsy = falsy
  @location = location
  @comments = []
end
Public Instance Methods

Source

def ===(other)
  other.is_a?(IfOp) && predicate === other.predicate &&
    truthy === other.truthy && falsy === other.falsy
end

Source

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

Source

def child_nodes
  [predicate, truthy, falsy]
end

Source

def copy(predicate: nil, truthy: nil, falsy: nil, location: nil)
  node =
    IfOp.new(
      predicate: predicate || self.predicate,
      truthy: truthy || self.truthy,
      falsy: falsy || self.falsy,
      location: location || self.location
    )

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

Source

def deconstruct_keys(_keys)
  {
    predicate: predicate,
    truthy: truthy,
    falsy: falsy,
    location: location,
    comments: comments
  }
end

Source

def format(q)
  force_flat = [
    AliasNode,
    Assign,
    Break,
    Command,
    CommandCall,
    Heredoc,
    IfNode,
    IfOp,
    Lambda,
    MAssign,
    Next,
    OpAssign,
    RescueMod,
    ReturnNode,
    Super,
    Undef,
    UnlessNode,
    VoidStmt,
    YieldNode,
    ZSuper
  ]

  if q.parent.is_a?(Paren) || force_flat.include?(truthy.class) ||
       force_flat.include?(falsy.class)
    q.group { format_flat(q) }
    return
  end

  q.group { q.if_break { format_break(q) }.if_flat { format_flat(q) } }
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