Method: BOAST::If#initialize

Defined in:
lib/BOAST/Language/If.rb

#initialize(condition, &block) ⇒ If #initialize(conditions, &block) ⇒ If

Creates a new instance of the If construct

Overloads:

  • #initialize(condition, &block) ⇒ If

    Creates a simple If construct

    Parameters:

    • condition (Expression)
    • block (Proc, nil)

      if given, will be evaluated when #pr is called

  • #initialize(conditions, &block) ⇒ If

    Creates a multi-condition If construct

    Parameters:

    • conditions (Hash{Expression, :else => Proc})

      each condition and its associated block (can be nil)

    • block (Proc, nil)

      else block if :else is not specified in the conditions or nil



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/BOAST/Language/If.rb', line 17

def initialize(conditions, &block)
  super()
  @conditions = []
  @blocks = []
  if conditions.is_a?(Hash) then
    else_block = conditions.delete(:else)
    else_block = block unless else_block or not block
    conditions.each { |key, value|
      @conditions.push key
      @blocks.push value
    }
    @blocks.push else_block if else_block
  else
    @conditions.push conditions
    @blocks.push block if block
  end
end