lib/exec_if.rb in exec_if-0.1.0 vs lib/exec_if.rb in exec_if-0.2.0
- old
+ new
@@ -1,11 +1,18 @@
require "exec_if/version"
class Object
def exec_if(obj, &blk)
- if obj
- blk.call(self, obj)
- else
+ case obj
+ when Proc
+ obj.call(self) ? blk.call(self, obj) : self
+ when Symbol
+ public_send(obj) ? blk.call(self, obj) : self
+ when String
+ eval(obj) ? blk.call(self, obj) : self
+ when Object
+ obj ? blk.call(self, obj) : self
+ when nil, false
self
end
end
end