Module: TEALrb::IfMethods

Defined in:
lib/tealrb/if_block.rb

Instance Method Summary collapse

Instance Method Details

#else(&blk) ⇒ Object



30
31
32
33
34
# File 'lib/tealrb/if_block.rb', line 30

def else(&blk)
  @teal.delete @end_label
  blk.call
  @teal << @end_label
end

#elsif(_cond, &blk) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/tealrb/if_block.rb', line 19

def elsif(_cond, &blk)
  @else_count += 1
  @teal.delete @end_label
  @teal << "bz if#{@if_count}_else#{@else_count}"
  blk.call
  @teal << "b if#{@if_count}_end"
  @teal << "if#{@if_count}_else#{@else_count}:"
  @teal << @end_label
  self
end

#teal_if(_cond, &blk) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tealrb/if_block.rb', line 5

def teal_if(_cond, &blk)
  @if_count ||= -1
  @if_count += 1
  @else_count = 0
  @end_label = "if#{@if_count}_end:"

  @teal << "bz if#{@if_count}_else0"
  blk.call
  @teal << "b if#{@if_count}_end"
  @teal << "if#{@if_count}_else0:"
  @teal << @end_label
  self
end