#!/usr/bin/env ruby # -*- encoding: utf-8 -*- # Copyright Steffie Dorn , 2017 # License: GNU APGLv3 (or later) class Object def blank? respond_to?(:empty?) ? !!empty? : !self end def present? !blank? end def nil_if_blank self.blank? ? nil : self end end class NilClass ; def blank? ; true ; end ; end class FalseClass ; def blank? ; true ; end ; end class TrueClass ; def blank? ; false ; end ; end class Numeric ; def blank? ; false ; end ; end class Time ; def blank? ; false ; end ; end class Array ; alias_method :blank?, :empty? ; end class Hash ; alias_method :blank?, :empty? ; end class String BLANK_RE = /\A[[:space:]]*\z/ def blank? empty? || BLANK_RE.match?(self) end end