Sha256: 15f703c668e2695304ae7d496c8e6ad437d13f61a0ce1d391d2ac3c150618fdd

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

module Koalemos
  module Blank
    module Object
      def blank?
        respond_to?(:empty?) ? empty? : !self
      end

      def present?
        !blank?
      end
    end

    module NilClass
      def blank?
        true
      end
    end

    module FalseClass
      def blank?
        true
      end
    end

    module TrueClass
      def blank?
        false
      end
    end

    module Array
      def self.included(modul)
        modul.module_eval do
          alias_method :blank?, :empty?
        end
      end
    end

    module Hash
      def self.included(modul)
        modul.module_eval do
          alias_method :blank?, :empty?
        end
      end
    end

    module String
      def blank?
        self !~ /\S/
      end
    end

    module Numeric
      def blank?
        false
      end
    end
  end

  unless Object.respond_to?(:blank?)
    for k in Blank.constants
      Object.const_get(k).class_eval do
        include Blank.const_get(k)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
koalemos-0.0.2 lib/koalemos/blank.rb
koalemos-0.0.1 lib/koalemos/blank.rb