Module: Tins::Full
- Defined in:
- lib/tins/xt/full.rb
Overview
Provides methods for checking if objects are “full” (non-blank) and safely processing them in conditional contexts.
This module adds the ‘full?` and `all_full?` methods to all objects, enabling clean, readable patterns for validation and conditional processing.
Instance Method Summary collapse
-
#all_full? ⇒ Object?
Checks if all elements in a collection are “full” (not blank).
-
#full?(dispatch = nil, *args) {|Object| ... } ⇒ Object?
Checks if the object is not blank, returning the object itself if it’s full, or nil if it’s blank.
Instance Method Details
#all_full? ⇒ Object?
Checks if all elements in a collection are “full” (not blank). If the object responds to all?
and all elements pass the full?
test, then the block is executed with the collection itself or the collection is returned.
74 75 76 77 78 |
# File 'lib/tins/xt/full.rb', line 74 def all_full? if respond_to?(:all?) && all?(&:full?) block_given? ? yield(self) : self end end |
#full?(dispatch = nil, *args) {|Object| ... } ⇒ Object?
Checks if the object is not blank, returning the object itself if it’s full, or nil if it’s blank. If a method name is provided as dispatch
, that method is called on the object and the result is checked for being full.
dispatched result not nil
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tins/xt/full.rb', line 46 def full?(dispatch = nil, *args) if blank? obj = nil 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 |