Module: AE::Subjunctive

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

Overview

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

THIS IS AN OPTIONAL LIBRARY.

Instance Method Summary collapse

Instance Method Details

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

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



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ae/subjunctive.rb', line 44

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 if provided and no block, uses #equate? to compare the argument to the receiver. This allows for statements of the form:

5.should.be Numeric


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ae/subjunctive.rb', line 21

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