Module: Assay::AE::Subjunctive

Included in:
Assertor
Defined in:
lib/assay/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'.

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
55
# File 'lib/assay/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
    match = args.shift
    pass  = (match === @delegate) # case equality
    msg   = args.shift || @message || ::Kernel.proc { "#{'! ' if @negated}#{__inspect__(match)} === #{__inspect__(@delegate)}" }
  end
  __assert__(pass, msg, ::CaseAssay)
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


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

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
    match = args.shift
    pass  = match.equate?(@delegate)
    msg   = args.shift || @message || ::Kernel.proc { "#{'! ' if @negated}#{__inspect__(match)} equate? #{__inspect__(@delegate)}" }
  end
  __assert__(pass, msg)
end