Sha256: 40e68eecf133d635a62a6b6d6d48973da06995fbee60ca35a2e9b2390432a2ba

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

class Object

  unless defined?(Rails)
    def blank?
      object = self
      object = object.strip if respond_to?(:strip)
      respond_to?(:empty?) ? !!object.empty? : !object
    end
  end

  def false?
    self == false
  end

  def falsey?
    [false, nil, 0].include?(self)
  end

  def numeric?
    !to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil?
  end

  def palindrome?
    to_s == to_s.reverse
  end

  unless defined?(Rails)
    def present?
      !blank?
    end
  end

  def true?
    self == true
  end

  def truthy?
    !falsey?
  end

  unless defined?(Rails)
    def try(*a, &b)
      try!(*a, &b) if a.empty? || respond_to?(a.first)
    end
  end

  unless defined?(Rails)
    def try!(*a, &b)
      if a.empty? && block_given?
        b.arity.zero? ? instance_eval(&b) : yield(self)
      else
        public_send(*a, &b)
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_object-2.2.2 lib/active_object/object.rb