RubyNode conditionNode = comparisons.get(comparisons.size() - 1);
// As with the if nodes, we work backwards to make it left associative
for (int i = comparisons.size() - 2; i >= 0; i--) {
conditionNode = new OrNode(context, sourceSection, comparisons.get(i), conditionNode);
}
// Create the if node
final BooleanCastNode conditionCastNode = BooleanCastNodeFactory.create(context, sourceSection, conditionNode);
RubyNode thenNode;
if (when.getBodyNode() == null) {
thenNode = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject());
} else {
thenNode = when.getBodyNode().accept(this);
}
final IfNode ifNode = new IfNode(context, sourceSection, conditionCastNode, thenNode, elseNode);
// This if becomes the else for the next if
elseNode = ifNode;
}
final RubyNode ifNode = elseNode;
// A top-level block assigns the temp then runs the if
return SequenceNode.sequence(context, sourceSection, assignTemp, ifNode);
} else {
for (int n = node.getCases().size() - 1; n >= 0; n--) {
final org.jruby.ast.WhenNode when = (org.jruby.ast.WhenNode) node.getCases().get(n);
// Make a condition from the one or more expressions combined in an or expression
final List<org.jruby.ast.Node> expressions;
if (when.getExpressionNodes() instanceof org.jruby.ast.ListNode) {
expressions = when.getExpressionNodes().childNodes();
} else {
expressions = Arrays.asList(when.getExpressionNodes());
}
final List<RubyNode> tests = new ArrayList<>();
for (org.jruby.ast.Node expressionNode : expressions) {
final RubyNode rubyExpression = expressionNode.accept(this);
tests.add(rubyExpression);
}
RubyNode conditionNode = tests.get(tests.size() - 1);
// As with the if nodes, we work backwards to make it left associative
for (int i = tests.size() - 2; i >= 0; i--) {
conditionNode = new OrNode(context, sourceSection, tests.get(i), conditionNode);
}
// Create the if node
final BooleanCastNode conditionCastNode = BooleanCastNodeFactory.create(context, sourceSection, conditionNode);