Method: Object#aT_not

Defined in:
lib/y_support/typing/object/typing.rb

#aT_not(what_is_receiver = nil, how_comply = nil, &b) ⇒ Object

This method takes a block and fails with TypeError, unless the receiver causes the supplied block to return falsey value. Optional arguments customize customize the error message. First optional argument describes the receiver, the second one describes the tested duck type. If the criterion block takes at least one argument (or more arguments), the receiver is passed to it. If the criterion block takes no arguments (arity 0), it is executed inside the singleton class of the receiver (using #instance_exec method). If no block is given, it is checked, whether the object is falsey.



68
69
70
71
72
73
74
75
76
# File 'lib/y_support/typing/object/typing.rb', line 68

def aT_not what_is_receiver=nil, how_comply=nil, &b
  if block_given? then
    m = how_comply ? "%s must not #{how_comply}!" : "%s fails its duck type!"
    m %= if what_is_receiver then what_is_receiver.to_s.capitalize else
           "#{self.class} instance #{object_id}"
         end
    tap { fail TypeError, m if b.( self ) }
  else tap { fail TypeError if self } end
end