Module: Nuggets::Object::BlankMixin

Included in:
Object
Defined in:
lib/nuggets/object/blank_mixin.rb

Instance Method Summary collapse

Instance Method Details

#blank?(*modifiers) ⇒ Boolean

call-seq:

object.blank? => true or false

Basically a short-cut to object.nil? || object.empty?.

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nuggets/object/blank_mixin.rb', line 36

def blank?(*modifiers)
  if block_given?
    return true if yield(dup).blank?
  end

  if modifiers.empty?
    respond_to?(:empty?) ? empty? : !self
  else
    return true if blank?

    modifiers.each { |modifier|
      if respond_to?(modifier)
        if modifier.to_s =~ /\?\z/
          return true if send(modifier)
        else
          return true if send(modifier).blank?
        end
      end
    }

    false
  end
end

#void?Boolean Also known as: vain?

call-seq:

object.void? => true or false

Adds white-space strings, 0 and arrays of nil objects to the list of blank objects.

Returns:

  • (Boolean)


65
66
67
# File 'lib/nuggets/object/blank_mixin.rb', line 65

def void?
  blank?(:zero?, :strip, :compact)
end