Sha256: e6efc57dba14bbb087304d8a8e07eb6377167a8073748f7d2477711575e6669c

Contents?: true

Size: 1020 Bytes

Versions: 162

Compression:

Stored size: 1020 Bytes

Contents

require 'tins/xt/blank'

module Tins
  module Full
    # Returns the object if it isn't blank (as in Object#blank?), otherwise it
    # returns nil. If a block was given as an argument and the object isn't
    # blank, the block is executed with the object as its first argument. If an
    # argument +dispatch+ was given and the object wasn't blank the method
    # given by dispatch is called on the object. This is the same as
    # foo.full?(&:bar) in the previous block form.
    def full?(dispatch = nil, *args)
      if blank?
        obj = nil
      #elsif Module === dispatch # TODO
      #  dispatch.found?(self)
      elsif dispatch
        obj = __send__(dispatch, *args)
        obj = nil if obj.blank?
      else
        obj = self
      end
      if block_given? and obj
        yield obj
      else
        obj
      end
    end

    def all_full?
      if respond_to?(:all?) && all?(&:full?)
        block_given? ? yield(self) : self
      end
    end
  end

  class ::Object
    include Full
  end
end

Version data entries

162 entries across 144 versions & 9 rubygems

Version Path
tins-1.37.0 lib/tins/xt/full.rb
tins-1.36.1 lib/tins/xt/full.rb
tins-1.36.0 lib/tins/xt/full.rb
tins-1.35.0 lib/tins/xt/full.rb
tins-1.34.0 lib/tins/xt/full.rb
tins-1.33.0 lib/tins/xt/full.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/lib/tins/xt/full.rb
tins-1.32.1 lib/tins/xt/full.rb
tins-1.32.0 lib/tins/xt/full.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/lib/tins/xt/full.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/lib/tins/xt/full.rb
tins-1.31.1 lib/tins/xt/full.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/lib/tins/xt/full.rb
tins-1.31.0 lib/tins/xt/full.rb
tins-1.30.0 lib/tins/xt/full.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/lib/tins/xt/full.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/lib/tins/xt/full.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/lib/tins/xt/full.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/lib/tins/xt/full.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/tins-1.28.0/lib/tins/xt/full.rb