Class: Object
- Inherits:
- BasicObject
- Includes:
- InstanceExecHelper
- Defined in:
- lib/gems/validatable-1.6.7/lib/object_extension.rb,
lib/gems/tmail-1.2.3.1/lib/tmail/core_extensions.rb
Overview
:nodoc:
Defined Under Namespace
Modules: InstanceExecHelper
Instance Method Summary collapse
-
#blank? ⇒ Boolean
An object is blank if it’s nil, empty, or a whitespace string.
- #instance_eval_with_params(*args, &block) ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
An object is blank if it’s nil, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?
to
if !address.blank?
14 15 16 17 18 19 20 21 22 |
# File 'lib/gems/tmail-1.2.3.1/lib/tmail/core_extensions.rb', line 14 def blank? if respond_to?(:empty?) && respond_to?(:strip) empty? or strip.empty? elsif respond_to?(:empty?) empty? else !self end end |
#instance_eval_with_params(*args, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gems/validatable-1.6.7/lib/object_extension.rb', line 5 def instance_eval_with_params(*args, &block) begin old_critical, Thread.critical = Thread.critical, true n = 0 n += 1 while respond_to?(mname="__instance_exec#{n}") InstanceExecHelper.module_eval{ define_method(mname, &block) } ensure Thread.critical = old_critical end begin ret = send(mname, *args) ensure InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil end ret end |