Sha256: 86811d49e23c0cfbff87115aba0865c040069025b1e75b1233e15ceb4fab7aa3

Contents?: true

Size: 896 Bytes

Versions: 12

Compression:

Stored size: 896 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
  end

  class ::Object
    include Full
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
tins-0.3.11 lib/tins/xt/full.rb
tins-0.3.10 lib/tins/xt/full.rb
tins-0.3.9 lib/tins/xt/full.rb
tins-0.3.8 lib/tins/xt/full.rb
tins-0.3.7 lib/tins/xt/full.rb
tins-0.3.6 lib/tins/xt/full.rb
tins-0.3.5 lib/tins/xt/full.rb
tins-0.3.4 lib/tins/xt/full.rb
tins-0.3.3 lib/tins/xt/full.rb
tins-0.3.2 lib/tins/xt/full.rb
tins-0.3.1 lib/tins/xt/full.rb
tins-0.3.0 lib/tins/xt/full.rb