Sha256: 15a00722db79731b283796366ef9b93b880da6f51d3ad637a56b1e3670e1b562

Contents?: true

Size: 794 Bytes

Versions: 13

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

class Object

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

  def deep_dup
    duplicable? ? dup : self
  end

  def duplicable?
    true
  end

  def present?
    !blank?
  end

  def presence
    self if present?
  end

  def try(method_name = nil, *args, &block)
    if method_name.nil? && block
      block.arity.zero? ? instance_eval(&block) : yield(self)
    elsif respond_to?(method_name)
      public_send(method_name, *args, &block)
    end
  end

  def try!(method_name = nil, *args, &block)
    if method_name.nil? && block
      block.arity.zero? ? instance_eval(&block) : yield(self)
    else
      public_send(method_name, *args, &block)
    end
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lite-ruby-2.3.0 lib/lite/ruby/safe/object.rb
lite-ruby-2.2.0 lib/lite/ruby/safe/object.rb
lite-ruby-2.1.0 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.7 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.6 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.5 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.4 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.3 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.2 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.1 lib/lite/ruby/safe/object.rb
lite-ruby-2.0.0 lib/lite/ruby/safe/object.rb
lite-ruby-1.3.3 lib/lite/ruby/safe/object.rb
lite-ruby-1.3.2 lib/lite/ruby/safe/object.rb