Module: Tins::Full

Defined in:
lib/tins/xt/full.rb

Instance Method Summary collapse

Instance Method Details

#all_full?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/tins/xt/full.rb', line 29

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

#full?(dispatch = nil, *args) ⇒ Boolean

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.

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tins/xt/full.rb', line 11

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