Module: Kernel

Defined in:
lib/core_ext/then.rb

Overview

Some monkey patches extracted from MethodChain library https://github.com/gregwebs/methodchain

Instance Method Summary collapse

Instance Method Details

#then(*guards, &block) ⇒ Object

return self if self or any of the +guards+ evaluate to false, otherwise return the evaluation of the block


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/core_ext/then.rb', line 39

def then *guards, &block
  if guards.empty?
    return self if not self
  else
    guards.each do |cond|
      return self if not (send_as_function cond)
    end
  end

  block_given? ? yield_or_eval(&block) : self
end

#then_if(*args, &block) ⇒ Object


51
52
53
54
55
56
57
# File 'lib/core_ext/then.rb', line 51

def then_if(*args, &block)
  if args.all?
    self.then(&block)
  else
    self
  end
end