class SyntaxTree::IfOp
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/syntax_tree/node.rbs class SyntaxTree::IfOp < SyntaxTree::Node def accept: (Visitor visitor) -> untyped def initialize: (predicate: (SyntaxTree::CallNode | SyntaxTree::ARef), truthy: SyntaxTree::StringLiteral, falsy: (SyntaxTree::CallNode | SyntaxTree::StringLiteral), location: SyntaxTree::Location) -> void end
predicate ? truthy : falsy
IfOp represents a ternary clause.
def ===(other)
def ===(other) other.is_a?(IfOp) && predicate === other.predicate && truthy === other.truthy && falsy === other.falsy end
def accept(visitor)
Experimental RBS support (using type sampling data from the type_fusion
project).
def accept: (Visitor visitor) -> untyped
This signature was generated using 1 sample from 1 application.
def accept(visitor) visitor.visit_if_op(self) end
def child_nodes
def child_nodes [predicate, truthy, falsy] end
def copy(predicate: nil, truthy: nil, falsy: nil, location: nil)
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
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { predicate: predicate, truthy: truthy, falsy: falsy, location: location, comments: comments } end
def format(q)
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
def format_break(q)
def format_break(q) Parentheses.break(q) do q.text("if ") q.nest("if ".length) { q.format(predicate) } q.indent do q.breakable_space q.format(truthy) end q.breakable_space q.text("else") q.indent do q.breakable_space q.format(falsy) end q.breakable_space q.text("end") end end
def format_flat(q)
def format_flat(q) q.format(predicate) q.text(" ?") q.indent do q.breakable_space q.format(truthy) q.text(" :") q.breakable_space q.format(falsy) end end
def initialize(predicate:, truthy:, falsy:, location:)
Experimental RBS support (using type sampling data from the type_fusion
project).
def initialize: (predicate: (SyntaxTree::CallNode | SyntaxTree::ARef), truthy: SyntaxTree::StringLiteral, falsy: (SyntaxTree::CallNode | SyntaxTree::StringLiteral), location: SyntaxTree::Location) -> void
This signature was generated using 2 samples from 1 application.
def initialize(predicate:, truthy:, falsy:, location:) @predicate = predicate @truthy = truthy @falsy = falsy @location = location @comments = [] end