Module: AE::Subjunctive

Included in:
Assertor
Defined in:
lib/ae/subjunctive.rb

Overview

Note:

THIS IS AN OPTIONAL LIBRARY.

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’.

Instance Method Summary collapse

Instance Method Details

#a(*args, &block) ⇒ Object Also known as: an

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



43
44
45
46
47
48
49
50
51
52
53
54
# 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

#be(*args, &block) ⇒ Object Also known as: is, does

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


20
21
22
23
24
25
26
27
28
29
30
31
# 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