Class: Object

Inherits:
BasicObject
Defined in:
lib/exec_if.rb

Instance Method Summary collapse

Instance Method Details

#exec_if(obj, &blk) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/exec_if.rb', line 2

def exec_if(obj, &blk)
  case obj
  when Proc
    obj.call(self) ? instance_exec(obj, &blk) : self
  when Symbol
    public_send(obj) ? instance_exec(obj, &blk) : self
  when String
    instance_eval(obj) ? instance_exec(obj, &blk) : self
  when Object
    obj ? instance_exec(obj, &blk) : self
  when nil, false
    self
  end
end