Sha256: 58ec7c611e095fa33130a0c4bd187beb66f23a5c233ce98464cfdf89a51348c1

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

class Object

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

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

  def palindrome?
    to_s == to_s.reverse
  end

  unless method_defined?(:present?)
    def present?
      !blank?
    end
  end

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

  unless method_defined?(:try!)
    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

2 entries across 2 versions & 1 rubygems

Version Path
active_object-1.0.1 lib/active_object/object.rb
active_object-1.0.0 lib/active_object/object.rb