Sha256: 061f0bfedd11eee5feeffccec8ac3537edd0604558bda6d2dd6db8013bc15b25

Contents?: true

Size: 899 Bytes

Versions: 15

Compression:

Stored size: 899 Bytes

Contents

require 'spruz/xt/blank'

module Spruz
  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

15 entries across 15 versions & 1 rubygems

Version Path
spruz-0.2.11 lib/spruz/xt/full.rb
spruz-0.2.10 lib/spruz/xt/full.rb
spruz-0.2.9 lib/spruz/xt/full.rb
spruz-0.2.8 lib/spruz/xt/full.rb
spruz-0.2.7 lib/spruz/xt/full.rb
spruz-0.2.6 lib/spruz/xt/full.rb
spruz-0.2.5 lib/spruz/xt/full.rb
spruz-0.2.2 lib/spruz/xt/full.rb
spruz-0.2.1 lib/spruz/xt/full.rb
spruz-0.2.0 lib/spruz/xt/full.rb
spruz-0.1.5 lib/spruz/xt/full.rb
spruz-0.1.3 lib/spruz/xt/full.rb
spruz-0.1.2 lib/spruz/xt/full.rb
spruz-0.1.1 lib/spruz/xt/full.rb
spruz-0.1.0 lib/spruz/xt/full.rb