class Z80::ConditionalBlock

See Program.select.

Public Instance Methods

else(&block) click to toggle source

Evaluates a block in an anonymous namespace if the condition evaluates to false. Returns an instance of ConditionalBlock.

NOTE

The block should produce some code or raise an error without producing any code. Labels defined inside a block are not accessible from outside of the conditional block.

# File lib/z80/select.rb, line 44
def else(&block)
        raise Syntax, "Only one of `else' or `else_select` variant may be defined" unless @selection.else.nil?
        # create an empty +then+ variant that just passes.
        @selection.then = create_variant if @selection.then.nil?
        @selection.else = create_variant(&block)
        self
end
else_select(*args, &test) click to toggle source

Evaluates additional condition if the previous condition evaluates to false. Returns an instance of ConditionalBlock.

See Program.select.

# File lib/z80/select.rb, line 57
def else_select(*args, &test)
        raise Syntax, "Only one of `else' or `else_select` variant may be defined" unless @selection.else.nil?
        # create an empty +then+ variant that just passes.
        @selection.then = create_variant if @selection.then.nil?
        ConditionalBlock.new(@program, *args, address: @address, codesize: @codesize, &test).tap do |cond|
                @selection.else = cond.selection
        end
end
then(&block) click to toggle source

Evaluates a block in an anonymous namespace if the condition evaluates to true. Returns an instance of ConditionalBlock.

NOTE

The block should produce some code or raise an error without producing any code. Labels defined inside a block are not accessible from outside of the conditional block.

# File lib/z80/select.rb, line 32
def then(&block)
        raise Syntax, "`then' variant may be defined only once" unless @selection.then.nil?
        @selection.then = create_variant(&block)
        self
end