module AE::Subjunctive

Subjunctive

Mixin for Assertor that provides additional English-eque verbage such as ‘be’ and ‘an’. This makes it easier to create assertor methods of subjunctive terms like ‘should’.

@note THIS IS AN OPTIONAL LIBRARY.

Public Instance Methods

a(*args, &block) click to toggle source

The indefinite article is like be, except that it compares a lone argument with case?, rather than equate?

# File lib/ae/subjunctive.rb, line 43
def a(*args, &block)
  return self if args.empty? && !block
  block = args.shift if !block && ::Proc === args.first
  if block
    pass = block.arity > 0 ? block.call(@delegate) : block.call  #@delegate.instance_eval(&block)
    msg = args.shift || @message || block.inspect
  else
    pass = (args.shift === @delegate) # case equality
    msg  = args.shift
  end
  __assert__(pass, msg)
end
Also aliased as: an
an(*args, &block)
Alias for: a
be(*args, &block) click to toggle source

Like assert, except if an argument is provided and no block, uses equate? to compare the argument to the receiver. This allows for statements of the form:

5.should.be Numeric
# File lib/ae/subjunctive.rb, line 20
def be(*args, &block)
  return self if args.empty? && !block
  block = args.shift if !block && ::Proc === args.first
  if block
    pass = block.arity > 0 ? block.call(@delegate) : block.call  #@delegate.instance_eval(&block)
    msg = args.shift || @message || block.inspect
  else
    pass = args.shift.equate?(@delegate)
    msg  = args.shift
  end
  __assert__(pass, msg)
end
Also aliased as: is, does
does(*args, &block)
Alias for: be
is(*args, &block)

Alias of be.

5.assert.is Numeric
Alias for: be