Class CaseExpr
A case
statement. There are three forms of case
statements:
# a value-less case expression acting like an if-elsif expression:
case
when x == 0 then puts "zero"
when x > 0 then puts "positive"
else puts "negative"
end
# a case expression that matches a value using `when` clauses:
case value
when 1, 2 then puts "a is one or two"
when 3 then puts "a is three"
else puts "I don't know what a is"
end
# a case expression that matches a value against patterns using `in` clauses:
config = {db: {user: 'admin', password: 'abc123'}}
case config
in db: {user:} # matches subhash and puts matched value in variable user
puts "Connect with user '#{user}'"
in connection: {username: } unless username == 'admin'
puts "Connect with user '#{username}'"
else
puts "Unrecognized structure of config"
end
Import path
import codeql.ruby.AST
Direct supertypes
Known direct subtypes
Predicates
getABranch | Gets a branch of this case expression, either a |
getAChild | Gets a child of this node, which can also be retrieved using a predicate named |
getAPrimaryQlClass | Gets the name of a primary CodeQL class to which this node belongs. |
getBranch | Gets the |
getElseBranch | Gets the |
getNumberOfBranches | Gets the number of branches of this case expression. |
getValue | Gets the expression being compared, if any. For example, |
toString | Gets a textual representation of this node. |
Inherited predicates
getAChild | Gets a child node of this | from AstNode |
getAControlFlowEntryNode | Gets a control-flow entry node for this statement, if any | from Stmt |
getAControlFlowNode | Gets a control-flow node for this statement, if any. | from Stmt |
getCfgScope | Gets the control-flow scope of this statement, if any. | from Stmt |
getConstantValue | Gets the constant value of this expression, if any. | from Expr |
getDesugared | Gets the desugared version of this AST node, if any. | from AstNode |
getEnclosingCallable | Gets the enclosing callable, if any. | from Stmt |
getEnclosingMethod | Gets the enclosing method, if any. | from AstNode |
getEnclosingModule | Gets the enclosing module, if any. | from AstNode |
getEnclosingToplevel | Gets the enclosing top-level. | from AstNode |
getFile | Gets the file of this node. | from AstNode |
getLocation | Gets the location of this node. | from AstNode |
getParent | Gets the parent of this | from AstNode |
getPrimaryQlClasses | Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. | from AstNode |
isSynthesized | Holds if this node was synthesized to represent an implicit AST node not present in the source code. In the following example method call, the receiver is an implicit | from AstNode |