class Rufo::Formatter
def visit_if_or_unless(node, keyword, check_end: true)
def visit_if_or_unless(node, keyword, check_end: true) # if cond # then_body # else # else_body # end # # [:if, cond, then, else] line = @line consume_keyword(keyword) consume_space visit node[1] skip_space indent_body node[2] if else_body = node[3] # [:else, else_contents] # [:elsif, cond, then, else] write_indent case else_body[0] when :else consume_keyword "else" indent_body else_body[1] when :elsif visit_if_or_unless else_body, "elsif", check_end: false else bug "expected else or elsif, not #{else_body[0]}" end end if check_end write_indent if @line != line consume_keyword "end" end end