Class: Fukubukuro::IfCondition

Inherits:
Statement show all
Defined in:
lib/amber/fukubukuro.rb

Class Method Summary collapse

Class Method Details

.new(condition, true_block, false_block = nil) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/amber/fukubukuro.rb', line 198

def self.new condition, true_block, false_block = nil
  if true_block && false_block
    super() do
      if condition.call.true?
        true_block.call
      else
        false_block.call
      end
    end
  elsif true_block
    super() do
      true_block.call if condition.call.true?
    end
  elsif false_block
    super() do
      false_block.call if condition.call.false?
    end
  else
    super() do
      condition.call
    end
  end
end