Sha256: 9bf8f753bec8c0c07127e764c125b933f1aba124650f22a45e4156ea62a81483

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module ActiveObject::Object

  def array?
    is_a?(Array)
  end

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

  def boolean?
    [false, "false", true, "true", nil, 0, "0", 1, "1"].include?(self)
  end

  def false?
    self == false
  end

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

  def float?
    is_a?(Float)
  end

  def hash?
    is_a?(Hash)
  end

  def integer?
    is_a?(Integer)
  end

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

  def numeric?
    is_a?(Numeric)
  end

  def palindrome?
    to_s == to_s.reverse
  end

  def present?
    !blank?
  end

  def range?
    is_a?(Range)
  end

  def salvage(placeholder="---")
    blank? ? placeholder : self
  end

  def string?
    is_a?(String)
  end

  def time?
    is_a?(Time)
  end

  def true?
    self == true
  end

  def truthy?
    !falsey?
  end

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

  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

Object.send(:include, ActiveObject::Object) if ActiveObject.configuration.autoload_object

Version data entries

1 entries across 1 versions & 1 rubygems

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